BuilderGUI.m 146 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425
  1. function varargout = BuilderGUI(varargin)
  2. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  3. % Compiles input files & analysis settings for pipeline. %
  4. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  5. % Copyright (C) 2013-2014, Michael J. Cheung
  6. %
  7. % This file is a part of the MEG & PLS Pipeline (MEGPLS). For more
  8. % details, see the documentation included with the software package.
  9. %
  10. % MEGPLS is free software: you can redistribute it and/or modify it under
  11. % the terms of the GNU General Public License version 2 as published by
  12. % the Free Software Foundation. This program is distributed in the hope
  13. % that it will be useful, but WITHOUT ANY WARRANTY; without even the
  14. % implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  15. % See the GNU General Public License for more details.
  16. %
  17. % You should have received a copy of the GNU General Public License along
  18. % with this program. If not, you can download the license here:
  19. % <http://www.gnu.org/licenses/old-licenses/gpl-2.0>.
  20. % Last Modified by GUIDE v2.5 13-Mar-2014 14:35:40
  21. % Begin initialization code - DO NOT EDIT
  22. gui_Singleton = 1;
  23. gui_State = struct('gui_Name', mfilename, ...
  24. 'gui_Singleton', gui_Singleton, ...
  25. 'gui_OpeningFcn', @BuilderGUI_OpeningFcn, ...
  26. 'gui_OutputFcn', @BuilderGUI_OutputFcn, ...
  27. 'gui_LayoutFcn', [] , ...
  28. 'gui_Callback', []);
  29. if nargin && ischar(varargin{1})
  30. gui_State.gui_Callback = str2func(varargin{1});
  31. end
  32. if nargout
  33. [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
  34. else
  35. gui_mainfcn(gui_State, varargin{:});
  36. end
  37. % End initialization code - DO NOT EDIT
  38. %--- Executes just before BuilderGUI is made visible. ---%
  39. %--------------------------------------------------------%
  40. function BuilderGUI_OpeningFcn(hObject, eventdata, handles, varargin)
  41. % This function has no output args, see OutputFcn.
  42. % hObject handle to figure
  43. % eventdata reserved - to be defined in a future version of MATLAB
  44. % handles structure with handles and user data (see GUIDATA)
  45. % varargin command line arguments to BuilderGUI (see VARARGIN)
  46. % Choose default command line output for BuilderGUI
  47. handles.output = hObject;
  48. % Make sure toolbox paths are added:
  49. [PipelineDir, ~, ~] = fileparts(which('BuilderGUI.m'));
  50. handles.PipelineDir = PipelineDir;
  51. addpath(genpath(PipelineDir));
  52. rmpath([PipelineDir,'/DEFAULT_SETTINGS']); % Make sure its calling from AnalysisID
  53. rmpath([PipelineDir,'/TEMPORARY_FIXES']); % Make sure its calling from FT toolbox
  54. CheckToolboxPaths(PipelineDir);
  55. if exist('ErrorLog_BuilderGUI.txt', 'file')
  56. system('rm ErrorLog_BuilderGUI.txt');
  57. end
  58. % Initializes variables being displayed:
  59. handles.paths.Rootpath = [];
  60. handles.name.AnalysisID = [];
  61. handles.paths.AnalysisID = [];
  62. handles.name.GroupID = [];
  63. handles.name.SubjID = [];
  64. handles.name.CondID = [];
  65. handles.gui.MEGdataFiletype = 'Fieldtrip';
  66. handles.gui.AnatID = [];
  67. handles.gui.InputAnatFiles = [];
  68. handles.gui.InputDataFiles = [];
  69. handles.gui.StatusAnat = [];
  70. handles.gui.StatusData = [];
  71. handles.gui.CheckICAclean = []; % For input FT files, checks if ICAcleaned (for check at end).
  72. handles.gui.CommonFilterCondID = [];
  73. handles.gui.ControlCondID = [];
  74. handles.gui.CommonFiltDataFiles = [];
  75. handles.gui.ControlDataFiles = [];
  76. handles.time = [];
  77. handles.FTcfg = [];
  78. handles.PipeSettings = [];
  79. % Update handles structure
  80. guidata(hObject, handles);
  81. % UIWAIT makes BuilderGUI wait for user response (see UIRESUME)
  82. % uiwait(handles.figure1);
  83. %--- Outputs from this function are returned to the command line. ---%
  84. %--------------------------------------------------------------------%
  85. function varargout = BuilderGUI_OutputFcn(hObject, eventdata, handles)
  86. % varargout cell array for returning output args (see VARARGOUT);
  87. % hObject handle to figure
  88. % eventdata reserved - to be defined in a future version of MATLAB
  89. % handles structure with handles and user data (see GUIDATA)
  90. % Get default command line output from handles structure
  91. varargout{1} = handles.output;
  92. %=================================%
  93. % FUNCTIONS FOR SETTING ROOTPATH: %
  94. %=================================%
  95. %--- Executes on button press in ButtonSetRootpath. ---%
  96. %------------------------------------------------------%
  97. function ButtonSetRootpath_Callback(hObject, eventdata, handles)
  98. if ~isempty(handles.name.AnalysisID)
  99. prompt = {'WARNING:';
  100. 'Changing root directory will clear all current settings!'; '';
  101. 'Do you wish to continue?'};
  102. ChangeDir = questdlg(prompt, 'WARNING:', 'YES', 'NO', 'NO');
  103. if strcmp(ChangeDir, 'NO')
  104. return;
  105. end
  106. end
  107. % Select and set Rootpath:
  108. SelectedPath = uigetdir([], 'Select target directory:');
  109. if SelectedPath == 0
  110. return; % If user cancels
  111. end
  112. % Check if selected path has spaces (AFNI functions cannot read spaces):
  113. CheckSpaces = strfind(SelectedPath, ' ');
  114. if ~isempty(CheckSpaces)
  115. message = {'Error: Target directory selected contains spaces.';
  116. 'AFNI functions cannot read folder & file paths with spaces.';
  117. 'AFNI functions are required for file conversions later on.'};
  118. msgbox(message, 'Error:')
  119. return;
  120. end
  121. handles.paths.Rootpath = SelectedPath;
  122. set(handles.TextboxRootpath, 'String', handles.paths.Rootpath);
  123. % Start Waitbox:
  124. WaitBox = StartWaitBox('SETTING TARGET DIRECTORY:');
  125. % Disable buttons for settings .m files: ** Upgrade to subgui
  126. set(handles.ButtonHdmAdvSettings, 'Enable', 'off');
  127. set(handles.ButtonTimelockFreqAdvSettings, 'Enable', 'off');
  128. set(handles.ButtonSourceAdvSettings, 'Enable', 'off');
  129. set(handles.ButtonNormSettings, 'Enable', 'off');
  130. % Reset AnalysisID:
  131. handles.name.AnalysisID = [];
  132. handles.paths.AnalysisID = [];
  133. set(handles.TextboxAnalysisID, 'String', 'Not Selected.');
  134. % Reset all input and settings:
  135. handles = ResetGroupIDSettings (handles);
  136. handles = ResetSubjIDSettings (handles);
  137. handles = ResetCondIDSettings (handles);
  138. handles = ResetInputMRI (handles);
  139. handles = ResetInputMEG (handles);
  140. handles = ResetTimeSettings (handles);
  141. handles = ResetHdmLeadSettings (handles);
  142. handles = ResetTimeFreqSettings (handles);
  143. handles = ResetSourceSettings (handles);
  144. handles = ResetNiftiAfniSettings (handles);
  145. % Redetect RootpathFolders & available CondIDs:
  146. handles = DetectRootpathFolders (handles);
  147. handles = DetectCondIDFolders (handles);
  148. % Update input and settings:
  149. handles = UpdateGroupIDSettings (handles);
  150. handles = UpdateSubjIDSettings (handles);
  151. handles = UpdateCondIDSettings (handles);
  152. handles = UpdateInputMRI (handles);
  153. handles = UpdateInputMEG (handles);
  154. handles = UpdateTimeSettings (handles);
  155. handles = UpdateHdmLeadSettings (handles);
  156. handles = UpdateTimeFreqSettings (handles);
  157. handles = UpdateSourceSettings (handles);
  158. handles = UpdateNormaliseSettings (handles);
  159. handles = UpdateNiftiAfniSettings (handles);
  160. % Save handles:
  161. guidata(hObject, handles);
  162. close(WaitBox);
  163. %--- Textbox to display selected Rootpath: ---%
  164. %---------------------------------------------%
  165. function TextboxRootpath_Callback(hObject, eventdata, handles)
  166. EnteredText = get(handles.TextboxRootpath, 'String');
  167. if ~isequal(EnteredText, handles.paths.Rootpath)
  168. set(handles.TextboxRootpath, 'String', handles.paths.Rootpath);
  169. msgbox('Note: Use button to change Rootpath.')
  170. end
  171. %===============================================%
  172. % FUNCTIONS FOR CREATING OR LOADING ANALYSISID: %
  173. %===============================================%
  174. %--- Executes on button press in ButtonCreateAnalysisID. ---%
  175. %-----------------------------------------------------------%
  176. function ButtonCreateAnalysisID_Callback(hObject, eventdata, handles)
  177. if isempty(handles.paths.Rootpath)
  178. msgbox('Warning: Select root directory first.', 'Warning:');
  179. return;
  180. end
  181. % Enter name of AnalysisID:
  182. UserInput = inputdlg('Enter AnalysisID name:', 'Create new AnalysisID:');
  183. UserInput = deblank(UserInput);
  184. UserInput = regexprep(UserInput, '\s+', '_');
  185. if isempty(char(UserInput))
  186. return; % If user cancels
  187. end
  188. PathInputID = [handles.paths.Rootpath,'/AnalysisID_',UserInput{1}];
  189. if exist(PathInputID, 'dir')
  190. msgbox('Error: Specified AnalysisID already exists!', 'Error:')
  191. return;
  192. end
  193. % Create AnalysisID & advanced settings folder:
  194. status = mkdir([PathInputID,'/SETTINGS/']);
  195. if status == 0 % If mkdir failed
  196. msgbox('Error: Failed to create AnalysisID folder.', 'Error:')
  197. return;
  198. end
  199. % Create advanced settings .m files:
  200. DefaultSettingsDir = [handles.PipelineDir,'/DEFAULT_SETTINGS'];
  201. AdvSettingsFiles = {
  202. 'Settings_SegHdmLeadfield.m';
  203. 'Settings_TimelockFreqAnalysis.m';
  204. 'Settings_TimelockFreqPlot.m';
  205. 'Settings_SourceAnalysis.m';
  206. 'Settings_SourceNormalise.m'};
  207. for f = 1:length(AdvSettingsFiles)
  208. status = copyfile([DefaultSettingsDir,'/',AdvSettingsFiles{f}], ...
  209. [PathInputID,'/SETTINGS/'], 'f');
  210. if status == 0
  211. message = {'ERROR:'; '';
  212. 'Failed to create advanced settings .m files for AnalysisID.';
  213. 'Could not copy files from [MEG]PLS "DEFAULT_SETTINGS" directory.';
  214. 'Check for proper folder and file permissions.'};
  215. msgbox(message, 'ERROR:')
  216. rmdir(PathInputID, 's'); % Remove remnant folder
  217. return;
  218. end
  219. end
  220. set(handles.ButtonHdmAdvSettings, 'Enable', 'on');
  221. set(handles.ButtonTimelockFreqAdvSettings, 'Enable', 'on');
  222. set(handles.ButtonSourceAdvSettings, 'Enable', 'on');
  223. set(handles.ButtonNormSettings, 'Enable', 'on');
  224. % Set as current AnalysisID:
  225. handles.name.AnalysisID = UserInput{1};
  226. handles.paths.AnalysisID = PathInputID;
  227. set(handles.TextboxAnalysisID, 'String', handles.name.AnalysisID);
  228. % Start Waitbox:
  229. WaitBox = StartWaitBox('CREATING ANALYSIS ID:');
  230. % Reset all input and settings:
  231. handles = ResetGroupIDSettings (handles);
  232. handles = ResetSubjIDSettings (handles);
  233. handles = ResetCondIDSettings (handles);
  234. handles = ResetInputMRI (handles);
  235. handles = ResetInputMEG (handles);
  236. handles = ResetTimeSettings (handles);
  237. handles = ResetHdmLeadSettings (handles);
  238. handles = ResetTimeFreqSettings (handles);
  239. handles = ResetSourceSettings (handles);
  240. handles = ResetNiftiAfniSettings (handles);
  241. % Redetect RootpathFolders & available CondIDs:
  242. handles = DetectRootpathFolders (handles);
  243. handles = DetectCondIDFolders (handles);
  244. % Update input and settings:
  245. handles = UpdateGroupIDSettings (handles);
  246. handles = UpdateSubjIDSettings (handles);
  247. handles = UpdateCondIDSettings (handles);
  248. handles = UpdateInputMRI (handles);
  249. handles = UpdateInputMEG (handles);
  250. handles = UpdateTimeSettings (handles);
  251. handles = UpdateHdmLeadSettings (handles);
  252. handles = UpdateTimeFreqSettings (handles);
  253. handles = UpdateSourceSettings (handles);
  254. handles = UpdateNormaliseSettings (handles);
  255. handles = UpdateNiftiAfniSettings (handles);
  256. % Save handles:
  257. guidata(hObject, handles);
  258. close(WaitBox);
  259. %--- Executes on button press in ButtonLoadAnalysisID. ---%
  260. %---------------------------------------------------------%
  261. function ButtonLoadAnalysisID_Callback(hObject, eventdata, handles)
  262. if isempty(handles.paths.Rootpath)
  263. msgbox('Warning: Select root directory first.', 'Warning:');
  264. return;
  265. end
  266. % Acquire AnalysisID folders in currently selected rootpath:
  267. DetectedFolders = dir([handles.paths.Rootpath,'/AnalysisID_*']);
  268. RemoveIndex = [];
  269. for d = 1:length(DetectedFolders)
  270. if DetectedFolders(d).isdir ~= 1
  271. RemoveIndex = [RemoveIndex, d]; % Get unwanted indices
  272. end
  273. end
  274. DetectedFolders(RemoveIndex) = [];
  275. if isempty(DetectedFolders)
  276. msgbox('Error: No AnalysisID folders detected inside root dir.', 'Error:');
  277. return;
  278. end
  279. % List detected AnalysisID folders:
  280. DetectedFolders = {DetectedFolders.name};
  281. SelectedIndex = listdlg('PromptString', 'Select AnalysisID to load:',...
  282. 'ListSize', [300, 300], 'SelectionMode', 'single', 'ListString', DetectedFolders);
  283. if isempty(SelectedIndex)
  284. return; % If user cancels.
  285. end
  286. SelectedAnalysisID = DetectedFolders{SelectedIndex};
  287. SelectedAnalysisID(1:11) = []; % Remove "AnalysisID_" prefix to get just the ID.
  288. PathAnalysisID = [handles.paths.Rootpath,'/AnalysisID_',SelectedAnalysisID];
  289. % Check for advanced settings .m files:
  290. AdvSettingsFiles = {
  291. 'Settings_SegHdmLeadfield.m';
  292. 'Settings_TimelockFreqAnalysis.m';
  293. 'Settings_TimelockFreqPlot.m';
  294. 'Settings_SourceAnalysis.m';
  295. 'Settings_SourceNormalise.m'};
  296. for f = 1:length(AdvSettingsFiles)
  297. if ~exist([PathAnalysisID,'/SETTINGS/',AdvSettingsFiles{f}], 'file')
  298. message = {'ERROR:'; '';
  299. 'Failed to find advanced settings .m files for AnalysisID.';
  300. 'Create new AnalysisID or manually import settings .m files.'};
  301. msgbox(message, 'ERROR:');
  302. return;
  303. end
  304. end
  305. set(handles.ButtonHdmAdvSettings, 'Enable', 'on');
  306. set(handles.ButtonTimelockFreqAdvSettings, 'Enable', 'on');
  307. set(handles.ButtonSourceAdvSettings, 'Enable', 'on');
  308. set(handles.ButtonNormSettings, 'Enable', 'on');
  309. % Set as current AnalysisID:
  310. handles.name.AnalysisID = SelectedAnalysisID;
  311. handles.paths.AnalysisID = PathAnalysisID;
  312. set(handles.TextboxAnalysisID, 'String', handles.name.AnalysisID);
  313. % Start Waitbox:
  314. WaitBox = StartWaitBox('LOADING ANALYSIS ID:');
  315. % Reset all input and settings:
  316. handles = ResetGroupIDSettings (handles);
  317. handles = ResetSubjIDSettings (handles);
  318. handles = ResetCondIDSettings (handles);
  319. handles = ResetInputMRI (handles);
  320. handles = ResetInputMEG (handles);
  321. handles = ResetTimeSettings (handles);
  322. handles = ResetHdmLeadSettings (handles);
  323. handles = ResetTimeFreqSettings (handles);
  324. handles = ResetSourceSettings (handles);
  325. handles = ResetNiftiAfniSettings (handles);
  326. % Load Builder .mat for AnalysisID:
  327. BuilderFile = [handles.paths.AnalysisID,'/Builder_',handles.name.AnalysisID,'.mat'];
  328. if exist(BuilderFile, 'file')
  329. LoadedMat = load(BuilderFile);
  330. handles = LoadGroupIDSettings (handles, LoadedMat);
  331. handles = LoadSubjIDSettings (handles, LoadedMat);
  332. handles = LoadCondIDSettings (handles, LoadedMat);
  333. handles = LoadInputMRI (handles, LoadedMat);
  334. handles = LoadInputMEG (handles, LoadedMat);
  335. handles = LoadTimeSettings (handles, LoadedMat);
  336. handles = LoadHdmLeadSettings (handles, LoadedMat);
  337. handles = LoadTimeFreqSettings (handles, LoadedMat);
  338. handles = LoadSourceSettings (handles, LoadedMat);
  339. handles = LoadNormaliseSettings (handles, LoadedMat);
  340. handles = LoadNiftiAfniSettings (handles, LoadedMat);
  341. else
  342. message = {'WARNING:'; '';
  343. 'Builder .mat was not found for loaded AnalysisID.';
  344. 'Input and settings will need to be reselected.'};
  345. msgbox(message, 'WARNING:')
  346. end
  347. % Redetect RootpathFolders & available CondIDs:
  348. handles = DetectRootpathFolders (handles);
  349. handles = DetectCondIDFolders (handles);
  350. % Update input and settings:
  351. handles = UpdateGroupIDSettings (handles);
  352. handles = UpdateSubjIDSettings (handles);
  353. handles = UpdateCondIDSettings (handles);
  354. handles = UpdateInputMRI (handles); % DetectInputMRI already called in LoadInputMRI
  355. handles = UpdateInputMEG (handles); % DetectInputMEG already called in LoadInputMEG
  356. handles = UpdateTimeSettings (handles);
  357. handles = UpdateHdmLeadSettings (handles);
  358. handles = UpdateTimeFreqSettings (handles);
  359. handles = UpdateSourceSettings (handles);
  360. handles = UpdateNormaliseSettings (handles);
  361. handles = UpdateNiftiAfniSettings (handles);
  362. % Save handles:
  363. guidata(hObject, handles);
  364. close(WaitBox);
  365. %--- Textbox to display current AnalysisID: ---%
  366. %----------------------------------------------%
  367. function TextboxAnalysisID_Callback(hObject, eventdata, handles)
  368. EnteredText = get(handles.TextboxAnalysisID, 'String');
  369. if ~isequal(EnteredText, handles.name.AnalysisID)
  370. set(handles.TextboxAnalysisID, 'String', handles.name.AnalysisID);
  371. msgbox('Note: Use button to change AnalysisID.')
  372. end
  373. %========================================%
  374. % FUNCTIONS TO IMPORT OR RESET SETTINGS: %
  375. %========================================%
  376. %--- Executes on button press in ButtonImportSettings. ---%
  377. %---------------------------------------------------------%
  378. function ButtonImportSettings_Callback(hObject, eventdata, handles)
  379. if isempty(handles.paths.Rootpath)
  380. msgbox('Warning: Select root directory first.', 'Warning:');
  381. return;
  382. end
  383. if isempty(handles.name.AnalysisID) || isempty(handles.paths.AnalysisID)
  384. msgbox('Warning: Create or load AnalysisID first.', 'Warning:');
  385. return;
  386. end
  387. % Confirm load:
  388. prompt = {'WARNING:'; '';
  389. 'Loaded settings will overwrite preprocessing settings for current AnalysisID!';
  390. 'Advanced settings .m files for current AnalysisID will also be overwritten.'; '';
  391. 'Do you wish to continue?'};
  392. ContinueLoad = questdlg(prompt, 'WARNING:', 'YES', 'NO', 'NO');
  393. if strcmp(ContinueLoad, 'NO')
  394. return;
  395. end
  396. % Get AnalysisID folders in current Rootpath:
  397. DetectedFolders = dir([handles.paths.Rootpath,'/AnalysisID_*']);
  398. RemoveIndex = [];
  399. for d = 1:length(DetectedFolders)
  400. if DetectedFolders(d).isdir ~= 1
  401. RemoveIndex = [RemoveIndex, d]; % Get unwanted indices
  402. end
  403. end
  404. DetectedFolders(RemoveIndex) = [];
  405. if isempty(DetectedFolders)
  406. msgbox('Error: No AnalysisID folders detected inside root dir.', 'Error:');
  407. return;
  408. end
  409. % List AnalysisID folders to import settings from:
  410. DetectedFolders = {DetectedFolders.name};
  411. SelectedIndex = listdlg('PromptString', 'Import settings from:',...
  412. 'ListSize', [300, 300], 'SelectionMode', 'single', 'ListString', DetectedFolders);
  413. if isempty(SelectedIndex)
  414. return; % If user cancels.
  415. end
  416. SelectedAnalysisID = DetectedFolders{SelectedIndex};
  417. SelectedAnalysisID(1:11) = []; % Remove "AnalysisID_" prefix to get just the ID.
  418. PathSelectedAnalysisID = [handles.paths.Rootpath,'/AnalysisID_',SelectedAnalysisID];
  419. % Check if files exist for selected AnalysisID:
  420. BuilderFile = [PathSelectedAnalysisID,'/Builder_',SelectedAnalysisID,'.mat'];
  421. if ~exist(BuilderFile, 'file')
  422. msgbox('Error: Failed to find Builder .mat for selected AnalysisID.', 'Error:')
  423. return;
  424. end
  425. AdvSettingsFiles = {
  426. 'Settings_SegHdmLeadfield.m';
  427. 'Settings_TimelockFreqAnalysis.m';
  428. 'Settings_TimelockFreqPlot.m';
  429. 'Settings_SourceAnalysis.m';
  430. 'Settings_SourceNormalise.m'};
  431. for f = 1:length(AdvSettingsFiles)
  432. if ~exist([PathSelectedAnalysisID,'/SETTINGS/',AdvSettingsFiles{f}], 'file')
  433. msgbox('Error: Adv. settings .m file(s) missing for selected AnalysisID.', 'Error:')
  434. return;
  435. end
  436. end
  437. % Start Waitbox:
  438. WaitBox = StartWaitBox('LOADING PREPROC SETTINGS:');
  439. % Reset basic settings:
  440. handles = ResetTimeSettings (handles);
  441. handles = ResetHdmLeadSettings (handles);
  442. handles = ResetTimeFreqSettings (handles);
  443. handles = ResetSourceSettings (handles);
  444. handles = ResetNormaliseSettings (handles);
  445. handles = ResetNiftiAfniSettings (handles);
  446. % Import basic settings from builder .mat:
  447. LoadedMat = load(BuilderFile);
  448. handles = LoadTimeSettings (handles, LoadedMat);
  449. handles = LoadHdmLeadSettings (handles, LoadedMat);
  450. handles = LoadTimeFreqSettings (handles, LoadedMat);
  451. handles = LoadSourceSettings (handles, LoadedMat);
  452. handles = LoadNormaliseSettings (handles, LoadedMat);
  453. handles = LoadNiftiAfniSettings (handles, LoadedMat);
  454. % Import advanced settings .m files:
  455. for f = 1:length(AdvSettingsFiles)
  456. delete([handles.paths.AnalysisID,'/SETTINGS/',AdvSettingsFiles{f}]);
  457. status = copyfile([PathSelectedAnalysisID,'/SETTINGS/',AdvSettingsFiles{f}], ...
  458. [handles.paths.AnalysisID,'/SETTINGS/'], 'f');
  459. if status == 0
  460. msgbox('Error: Failed to import adv. settings from AnalysisID.', 'Error:')
  461. end
  462. end
  463. % Update settings:
  464. handles = UpdateTimeSettings (handles);
  465. handles = UpdateHdmLeadSettings (handles);
  466. handles = UpdateTimeFreqSettings (handles);
  467. handles = UpdateSourceSettings (handles);
  468. handles = UpdateNormaliseSettings (handles);
  469. handles = UpdateNiftiAfniSettings (handles);
  470. % Save handles:
  471. guidata(hObject, handles);
  472. close(WaitBox);
  473. %--- Executes on button press in ButtonResetSettings. ---%
  474. %--------------------------------------------------------%
  475. function ButtonResetSettings_Callback(hObject, eventdata, handles)
  476. if isempty(handles.paths.Rootpath)
  477. msgbox('Warning: Select root directory first.', 'Warning:');
  478. return;
  479. end
  480. if isempty(handles.name.AnalysisID) || isempty(handles.paths.AnalysisID)
  481. msgbox('Warning: Create or load AnalysisID first.', 'Warning:');
  482. return;
  483. end
  484. % Confirm reset:
  485. prompt = {'WARNING:'; '';
  486. 'You are about to reset all preprocessing settings for this AnalysisID.';
  487. 'Advanced settings .m files will for selected AnalysisID will also be reset.'; '';
  488. 'Do you wish to continue?'};
  489. ContinueReset = questdlg(prompt, 'WARNING:', 'YES', 'NO', 'NO');
  490. if strcmp(ContinueReset, 'NO')
  491. return;
  492. end
  493. % Reset advanced settings .m files:
  494. DefaultSettingsDir = [handles.PipelineDir,'/DEFAULT_SETTINGS'];
  495. AdvSettingsFiles = {
  496. 'Settings_SegHdmLeadfield.m';
  497. 'Settings_TimelockFreqAnalysis.m';
  498. 'Settings_TimelockFreqPlot.m';
  499. 'Settings_SourceAnalysis.m';
  500. 'Settings_SourceNormalise.m'};
  501. for f = 1:length(AdvSettingsFiles)
  502. delete([handles.paths.AnalysisID,'/SETTINGS/',AdvSettingsFiles{f}]);
  503. status = copyfile([DefaultSettingsDir,'/',AdvSettingsFiles{f}], ...
  504. [handles.paths.AnalysisID,'/SETTINGS/'], 'f');
  505. if status == 0
  506. msgbox('Error: Failed to reset adv. settings .m file(s).', 'Error:')
  507. return;
  508. end
  509. end
  510. % Start Waitbox:
  511. WaitBox = StartWaitBox('RESETTING PREPROC SETTINGS:');
  512. % Reset settings:
  513. handles = ResetTimeSettings (handles);
  514. handles = ResetHdmLeadSettings (handles);
  515. handles = ResetTimeFreqSettings (handles);
  516. handles = ResetSourceSettings (handles);
  517. handles = ResetNormaliseSettings (handles);
  518. handles = ResetNiftiAfniSettings (handles);
  519. % Update settings:
  520. handles = UpdateTimeSettings (handles);
  521. handles = UpdateHdmLeadSettings (handles);
  522. handles = UpdateTimeFreqSettings (handles);
  523. handles = UpdateSourceSettings (handles);
  524. handles = UpdateNormaliseSettings (handles);
  525. handles = UpdateNiftiAfniSettings (handles);
  526. % Save handles:
  527. guidata(hObject, handles);
  528. close(WaitBox);
  529. %==========================================%
  530. % FUNCTIONS FOR ADDING OR REMOVING GROUPS: %
  531. %==========================================%
  532. %--- Executes on selection change in ListboxGroupID. ---%
  533. %-------------------------------------------------------%
  534. function ListboxGroupID_Callback(hObject, eventdata, handles)
  535. handles = UpdateSubjIDSettings (handles);
  536. handles = UpdateInputMRI (handles);
  537. handles = UpdateInputMEG (handles);
  538. guidata(hObject, handles);
  539. %--- Executes on button press in ButtonAddGroupID. ---%
  540. %-----------------------------------------------------%
  541. function ButtonAddGroupID_Callback(hObject, eventdata, handles)
  542. if isempty(handles.paths.Rootpath)
  543. msgbox('Warning: Select target directory first.', 'Warning:');
  544. return;
  545. end
  546. if isempty(handles.name.AnalysisID) || isempty(handles.paths.AnalysisID)
  547. msgbox('Warning: Create or load AnalysisID first.', 'Warning:');
  548. return;
  549. end
  550. % Enter name of GroupID:
  551. UserInput = inputdlg('Enter GroupID name:', 'Manually specify GroupID:');
  552. UserInput = deblank(UserInput);
  553. UserInput = regexprep(UserInput, '\s+', '_');
  554. if isempty(char(UserInput))
  555. return; % If user cancels
  556. end
  557. InputGroupID = UserInput{1};
  558. if ismember(InputGroupID, handles.name.GroupID)
  559. msgbox('Note: GroupID has already been added.', 'Note:')
  560. return;
  561. end
  562. % Set GroupID:
  563. handles.name.GroupID = [handles.name.GroupID; cellstr(InputGroupID)];
  564. NewGroupIndex = length(handles.name.GroupID);
  565. handles.name.SubjID{NewGroupIndex} = []; % Initialize
  566. set(handles.ListboxGroupID, 'Value', NewGroupIndex);
  567. handles.gui.InputAnatFiles {NewGroupIndex} = [];
  568. handles.gui.StatusAnat {NewGroupIndex} = [];
  569. handles.gui.InputDataFiles {NewGroupIndex} = [];
  570. handles.gui.StatusData {NewGroupIndex} = [];
  571. handles.gui.CheckICAclean {NewGroupIndex} = [];
  572. % Update input files:
  573. handles = UpdateGroupIDSettings (handles);
  574. handles = UpdateSubjIDSettings (handles);
  575. handles = UpdateInputMRI (handles); % Only initialize, don't detect for now
  576. handles = UpdateInputMEG (handles); % so user does not have to wait between add.
  577. % Save handles:
  578. guidata(hObject, handles);
  579. %--- Executes on button press in ButtonRmvGroupID. ---%
  580. %-----------------------------------------------------%
  581. function ButtonRmvGroupID_Callback(hObject, eventdata, handles)
  582. if isempty(handles.name.GroupID)
  583. return;
  584. end
  585. SelectedIndex = get(handles.ListboxGroupID, 'Value');
  586. handles.name.GroupID (SelectedIndex) = [];
  587. handles.name.SubjID (SelectedIndex) = [];
  588. if ~isempty(handles.gui.InputAnatFiles)
  589. handles.gui.InputAnatFiles (SelectedIndex) = [];
  590. handles.gui.StatusAnat (SelectedIndex) = [];
  591. end
  592. if ~isempty(handles.gui.InputDataFiles)
  593. handles.gui.InputDataFiles (SelectedIndex) = [];
  594. handles.gui.StatusData (SelectedIndex) = [];
  595. handles.gui.CheckICAclean (SelectedIndex) = [];
  596. end
  597. % Update GUI & input files:
  598. handles = UpdateGroupIDSettings (handles);
  599. handles = UpdateSubjIDSettings (handles);
  600. handles = UpdateInputMRI (handles);
  601. handles = UpdateInputMEG (handles);
  602. % Save handles:
  603. guidata(hObject, handles);
  604. %--- Executes on button press in ButtonLoadGroupSubj. ---%
  605. %--------------------------------------------------------%
  606. function ButtonLoadGroupSubj_Callback(hObject, eventdata, handles)
  607. if isempty(handles.paths.Rootpath)
  608. msgbox('Warning: Select root directory first.', 'Warning:');
  609. return;
  610. end
  611. if isempty(handles.name.AnalysisID) || isempty(handles.paths.AnalysisID)
  612. msgbox('Warning: Create or load AnalysisID first.', 'Warning:');
  613. return;
  614. end
  615. % Load PreprocInput or Builder .mat:
  616. [matfile, matpath] = uigetfile({[handles.paths.Rootpath,...
  617. '/PreprocInputMRI_*.mat; PreprocInputMEG_*; Builder_*.mat']},...
  618. 'Load GroupID & SubjID from .mat file:', 'MultiSelect', 'off');
  619. if matfile == 0
  620. return; % If user cancels
  621. else
  622. LoadedMat = load([matpath,matfile]);
  623. end
  624. % Clear conflicting groups:
  625. if strfind(matfile, 'PreprocInput') == 1
  626. Overlap = find(ismember(handles.name.GroupID, LoadedMat.name.CurrentGroupID));
  627. elseif strfind(matfile, 'Builder_') == 1
  628. if ~isempty(handles.name.GroupID)
  629. Overlap = find(ismember(handles.name.GroupID, LoadedMat.name.GroupID));
  630. else
  631. Overlap = [];
  632. end
  633. else
  634. msgbox('Error: Unrecognized .mat type.', 'Error:')
  635. return;
  636. end
  637. if ~isempty(Overlap)
  638. handles.name.GroupID (Overlap) = [];
  639. handles.name.SubjID (Overlap) = [];
  640. end
  641. % Start Waitbox:
  642. WaitBox = StartWaitBox('LOADING GROUP & SUBJ INPUT:');
  643. % Load GroupID and SubjID:
  644. if strfind(matfile, 'PreprocInput') == 1
  645. handles.name.GroupID = [handles.name.GroupID; cellstr(LoadedMat.name.CurrentGroupID)];
  646. handles.name.SubjID = [handles.name.SubjID, {LoadedMat.name.SubjID}];
  647. elseif strfind(matfile, 'Builder_') == 1
  648. handles.name.GroupID = [handles.name.GroupID; LoadedMat.name.GroupID];
  649. handles.name.SubjID = [handles.name.SubjID, LoadedMat.name.SubjID];
  650. else
  651. msgbox('Error: Unrecognized .mat type.', 'Error:')
  652. return;
  653. end
  654. % Update Group & SubjIDs:
  655. handles = UpdateGroupIDSettings (handles);
  656. handles = UpdateSubjIDSettings (handles);
  657. % Detect input files & update status:
  658. for g = 1:length(handles.name.GroupID)
  659. DetectWaitbar = waitbar(0, ...
  660. ['Scanning input MRI files for: ',handles.name.GroupID{g}], 'Windowstyle', 'modal');
  661. for s = 1:length(handles.name.SubjID{g})
  662. waitbar(s/length(handles.name.SubjID{g}), DetectWaitbar);
  663. handles = DetectInputMRI(handles, g, s);
  664. end
  665. delete(DetectWaitbar)
  666. end
  667. for g = 1:length(handles.name.GroupID)
  668. DetectWaitbar = waitbar(0, ...
  669. ['Scanning input MEG files for: ',handles.name.GroupID{g}], 'Windowstyle', 'modal');
  670. for s = 1:length(handles.name.SubjID{g})
  671. waitbar(s/length(handles.name.SubjID{g}), DetectWaitbar);
  672. for c = 1:size(handles.gui.AddedCondIDs, 1)
  673. handles = DetectInputMEG(handles, g, s, c);
  674. end
  675. end
  676. delete(DetectWaitbar)
  677. end
  678. handles = UpdateInputMRI (handles);
  679. handles = UpdateInputMEG (handles);
  680. % Save handles:
  681. guidata(hObject, handles);
  682. close(WaitBox);
  683. %--- Update GroupID settings & GUI panel: ---%
  684. %--------------------------------------------%
  685. function OutputHandles = UpdateGroupIDSettings(InputHandles)
  686. handles = InputHandles;
  687. % Update listbox:
  688. set(handles.ListboxGroupID, 'String', handles.name.GroupID);
  689. CurrentIndex = get(handles.ListboxGroupID, 'Value');
  690. MaxGroupIndex = length(handles.name.GroupID);
  691. if isempty(CurrentIndex) || CurrentIndex == 0 || CurrentIndex > MaxGroupIndex
  692. set(handles.ListboxGroupID, 'Value', MaxGroupIndex);
  693. end
  694. % Set output handles:
  695. OutputHandles = handles;
  696. %--- Load GroupID settings & GUI panel: ---%
  697. %------------------------------------------%
  698. function OutputHandles = LoadGroupIDSettings(InputHandles, LoadedMat)
  699. handles = InputHandles;
  700. % Load GroupID and SubjID (Note: Overwrites unlike LoadGroupSubj):
  701. handles.name.GroupID = LoadedMat.name.GroupID;
  702. handles.name.SubjID = LoadedMat.name.SubjID;
  703. % Load GUI panel:
  704. set(handles.ListboxGroupID, 'String', handles.name.GroupID);
  705. set(handles.ListboxGroupID, 'Value', 1);
  706. set(handles.ListboxSubjID, 'String', handles.name.SubjID{1});
  707. set(handles.ListboxSubjID, 'Value', 1);
  708. % Set output handles:
  709. OutputHandles = handles;
  710. %--- Reset GroupID settings & GUI panel: ---%
  711. %-------------------------------------------%
  712. function OutputHandles = ResetGroupIDSettings(InputHandles)
  713. handles = InputHandles;
  714. handles.name.GroupID = [];
  715. set(handles.ListboxGroupID, 'String', []);
  716. set(handles.ListboxGroupID, 'Value', 1);
  717. % Set output handles:
  718. OutputHandles = handles;
  719. %=========================================%
  720. % FUNCTIONS FOR ADDING/REMOVING SUBJECTS: %
  721. %=========================================%
  722. %--- Executes on selection change in ListboxSubjID. ---%
  723. %------------------------------------------------------%
  724. function ListboxSubjID_Callback(hObject, eventdata, handles)
  725. SelectedIndex = get(handles.ListboxSubjID, 'Value');
  726. if ~isempty(handles.gui.InputAnatFiles)
  727. set(handles.ListboxInputMRI, 'Value', SelectedIndex);
  728. end
  729. if ~isempty(handles.gui.InputDataFiles)
  730. set(handles.ListboxInputMEG, 'Value', SelectedIndex);
  731. end
  732. %--- User enters subject to add into this textbox. ---%
  733. %-----------------------------------------------------%
  734. function TextboxSubjID_Callback(hObject, eventdata, handles)
  735. keypress = get(gcf,'CurrentCharacter');
  736. if isequal(keypress, char(13))
  737. ButtonAddSubjID_Callback(hObject, eventdata, handles);
  738. end
  739. %--- Executes on button press in ButtonAddSubjID. ---%
  740. %----------------------------------------------------%
  741. function ButtonAddSubjID_Callback(hObject, eventdata, handles)
  742. if isempty(handles.name.AnalysisID) || isempty(handles.paths.AnalysisID)
  743. msgbox('Warning: Create or load AnalysisID first.', 'Warning:');
  744. return;
  745. end
  746. if isempty(handles.name.GroupID)
  747. msgbox('Warning: Create or load a GroupID first.', 'Warning:');
  748. return;
  749. end
  750. % Read entered SubjID:
  751. InputSubjID = get(handles.TextboxSubjID, 'String');
  752. InputSubjID = deblank(InputSubjID);
  753. InputSubjID = regexprep(InputSubjID, '\s+', '_');
  754. InputSubjID = cellstr(InputSubjID);
  755. if isempty(InputSubjID{1})
  756. return;
  757. end
  758. GroupIndex = get(handles.ListboxGroupID, 'Value');
  759. if ismember(InputSubjID{1}, handles.name.SubjID{GroupIndex})
  760. return; % If SubjID already added
  761. end
  762. % Add SubjID for selected group:
  763. handles.name.SubjID{GroupIndex} = [handles.name.SubjID{GroupIndex}; InputSubjID];
  764. NewSubjIndex = length(handles.name.SubjID{GroupIndex});
  765. handles.gui.InputAnatFiles {GroupIndex}{NewSubjIndex} = [];
  766. handles.gui.StatusAnat {GroupIndex}{NewSubjIndex} = [];
  767. for c = 1:length(handles.name.CondID)
  768. handles.gui.InputDataFiles {GroupIndex}{NewSubjIndex,c} = [];
  769. handles.gui.StatusData {GroupIndex}{NewSubjIndex,c} = [];
  770. handles.gui.CheckICAclean {GroupIndex}{NewSubjIndex,c} = [];
  771. end
  772. % Update input files:
  773. handles = UpdateSubjIDSettings (handles);
  774. handles = UpdateInputMRI (handles); % Only initialize for now, don't detect
  775. handles = UpdateInputMEG (handles); % so user doesn't have to wait between adds.
  776. % Save handles:
  777. set(handles.ListboxSubjID, 'Value', NewSubjIndex);
  778. if ~isempty(handles.gui.InputAnatFiles)
  779. set(handles.ListboxInputMRI, 'Value', NewSubjIndex);
  780. end
  781. if ~isempty(handles.gui.InputDataFiles)
  782. set(handles.ListboxInputMEG, 'Value', NewSubjIndex);
  783. end
  784. guidata(hObject, handles);
  785. %--- Executes on button press in ButtonRmvSubjID. ---%
  786. %----------------------------------------------------%
  787. function ButtonRmvSubjID_Callback(hObject, eventdata, handles)
  788. if isempty(handles.name.SubjID)
  789. return;
  790. end
  791. GroupIndex = get(handles.ListboxGroupID, 'Value');
  792. SubjIndex = get(handles.ListboxSubjID, 'Value');
  793. if isempty(handles.name.SubjID{GroupIndex})
  794. return;
  795. end
  796. handles.name.SubjID{GroupIndex}(SubjIndex) = [];
  797. if ~isempty(handles.gui.InputAnatFiles)
  798. handles.gui.InputAnatFiles{GroupIndex}(SubjIndex) = [];
  799. handles.gui.StatusAnat{GroupIndex}(SubjIndex) = [];
  800. end
  801. if ~isempty(handles.name.CondID)
  802. handles.gui.InputDataFiles{GroupIndex}(SubjIndex,:) = [];
  803. handles.gui.StatusData{GroupIndex}(SubjIndex,:) = [];
  804. handles.gui.CheckICAclean{GroupIndex}(SubjIndex,:) = [];
  805. end
  806. % Update input files:
  807. handles = UpdateSubjIDSettings (handles);
  808. handles = UpdateInputMRI (handles);
  809. handles = UpdateInputMEG (handles);
  810. % Save handles:
  811. guidata(hObject, handles);
  812. %--- Update SubjID settings & GUI panel: ---%
  813. %-------------------------------------------%
  814. function OutputHandles = UpdateSubjIDSettings(InputHandles)
  815. handles = InputHandles;
  816. % Update listbox:
  817. GroupIndex = get(handles.ListboxGroupID, 'Value');
  818. if isempty(handles.name.SubjID)
  819. set(handles.ListboxSubjID, 'String', []);
  820. MaxSubjIndex = 0;
  821. else
  822. set(handles.ListboxSubjID, 'String', handles.name.SubjID{GroupIndex});
  823. MaxSubjIndex = length(handles.name.SubjID{GroupIndex});
  824. end
  825. SubjIndex = get(handles.ListboxSubjID, 'Value');
  826. if isempty(SubjIndex) || SubjIndex == 0 || SubjIndex > MaxSubjIndex
  827. set(handles.ListboxSubjID, 'Value', MaxSubjIndex);
  828. if ~isempty(handles.gui.InputAnatFiles)
  829. set(handles.ListboxInputMRI, 'Value', MaxSubjIndex);
  830. end
  831. if ~isempty(handles.gui.InputDataFiles)
  832. set(handles.ListboxInputMEG, 'Value', MaxSubjIndex);
  833. end
  834. end
  835. % Set output handles:
  836. OutputHandles = handles;
  837. %--- Load SubjID settings & GUI panel: ---%
  838. %-----------------------------------------%
  839. function OutputHandles = LoadSubjIDSettings(InputHandles, LoadedMat)
  840. handles = InputHandles;
  841. handles.name.SubjID = LoadedMat.name.SubjID;
  842. set(handles.ListboxSubjID, 'String', handles.name.SubjID{1});
  843. set(handles.ListboxSubjID, 'Value', 1);
  844. % Set output handles:
  845. OutputHandles = handles;
  846. %--- Reset SubjID settings & GUI panel: ---%
  847. %------------------------------------------%
  848. function OutputHandles = ResetSubjIDSettings(InputHandles)
  849. handles = InputHandles;
  850. handles.name.SubjID = [];
  851. set(handles.ListboxSubjID, 'String', []);
  852. set(handles.ListboxSubjID, 'Value', 1);
  853. % Set output handles:
  854. OutputHandles = handles;
  855. %========================================%
  856. % FUNCTIONS FOR MRI SELECTION & DISPLAY: %
  857. %========================================%
  858. %--- Executes on selection change in ListboxInputMRI. ---%
  859. %------------------------------------------------------------%
  860. function ListboxInputMRI_Callback(hObject, eventdata, handles)
  861. if isempty(handles.gui.InputAnatFiles)
  862. return;
  863. end
  864. SelectedIndex = get(handles.ListboxInputMRI, 'Value');
  865. set(handles.ListboxSubjID, 'Value', SelectedIndex);
  866. if ~isempty(handles.gui.InputDataFiles)
  867. set(handles.ListboxInputMEG, 'Value', SelectedIndex);
  868. end
  869. %--- Executes on button press in CheckboxShowPathMRI. ---%
  870. %------------------------------------------------------------%
  871. function CheckboxShowPathMRI_Callback(hObject, eventdata, handles)
  872. handles = UpdateInputMRI(handles);
  873. guidata(hObject, handles);
  874. %--- Executes on button press in ButtonSelectAnatIDFolder. ---%
  875. %-------------------------------------------------------------%
  876. function ButtonSelectAnatIDFolder_Callback(hObject, eventdata, handles)
  877. if isempty(handles.paths.Rootpath)
  878. msgbox('Warning: Select root directory first.', 'Warning:');
  879. return;
  880. end
  881. if isempty(handles.name.AnalysisID) || isempty(handles.paths.AnalysisID)
  882. msgbox('Warning: Create or load AnalysisID first.', 'Warning:');
  883. return;
  884. end
  885. % Get AnatID folders in current rootpath:
  886. DetectedFolders = dir([handles.paths.Rootpath,'/AnatID_*']);
  887. RemoveIndex = [];
  888. for d = 1:length(DetectedFolders)
  889. if DetectedFolders(d).isdir ~= 1
  890. RemoveIndex = [RemoveIndex, d]; % Get unwanted indices
  891. end
  892. end
  893. DetectedFolders(RemoveIndex) = [];
  894. if isempty(DetectedFolders)
  895. msgbox('Error: No AnatID folders detected inside root dir.', 'Error:');
  896. return;
  897. end
  898. % List AnatID folders for selection:
  899. DetectedFolders = {DetectedFolders.name};
  900. SelectedIndex = listdlg('PromptString', 'Select AnatID to load:',...
  901. 'ListSize', [300, 300], 'SelectionMode', 'single', 'ListString', DetectedFolders);
  902. if isempty(SelectedIndex)
  903. return; % If user cancels
  904. end
  905. % Set as current AnatID:
  906. SelectedAnatID = DetectedFolders{SelectedIndex};
  907. SelectedAnatID(1:7) = []; % Remove "AnatID_" prefix to get AnatID.
  908. handles.gui.AnatID = SelectedAnatID;
  909. % Detect input MRI files & update status:
  910. for g = 1:length(handles.name.GroupID)
  911. DetectWaitbar = waitbar(0, ...
  912. ['Scanning input MRI files for: ',handles.name.GroupID{g}], 'Windowstyle', 'modal');
  913. for s = 1:length(handles.name.SubjID{g})
  914. waitbar(s/length(handles.name.SubjID{g}), DetectWaitbar);
  915. handles = DetectInputMRI(handles, g, s);
  916. end
  917. delete(DetectWaitbar)
  918. end
  919. handles = UpdateInputMRI(handles);
  920. % Save handles:
  921. guidata(hObject, handles);
  922. %--- Executes on button press in ButtonDetectInputMRI. ---%
  923. %---------------------------------------------------------%
  924. function ButtonDetectInputMRI_Callback(hObject, eventdata, handles)
  925. % Detect input MRI files & update status:
  926. for g = 1:length(handles.name.GroupID)
  927. DetectWaitbar = waitbar(0, ...
  928. ['Scanning input MRI files for: ',handles.name.GroupID{g}], 'Windowstyle', 'modal');
  929. for s = 1:length(handles.name.SubjID{g})
  930. waitbar(s/length(handles.name.SubjID{g}), DetectWaitbar);
  931. handles = DetectInputMRI(handles, g, s);
  932. end
  933. delete(DetectWaitbar)
  934. end
  935. handles = UpdateInputMRI(handles);
  936. guidata(hObject, handles);
  937. %--- Detect input MRI files & status: ---%
  938. %----------------------------------------%
  939. function OutputHandles = DetectInputMRI(InputHandles, g, s)
  940. handles = InputHandles;
  941. % Update input MRI paths and status:
  942. handles.gui.InputAnatFiles{g}{s} = [];
  943. handles.gui.StatusAnat{g}{s} = [];
  944. if ~isempty(handles.gui.AnatID)
  945. Rootpath = handles.paths.Rootpath;
  946. AnatIDFolder = ['AnatID_',handles.gui.AnatID];
  947. GroupIDFolder = ['GroupID_',handles.name.GroupID{g}];
  948. Filename = [handles.name.SubjID{g}{s},'_PreprocMRI.mat'];
  949. handles.gui.InputAnatFiles{g}{s} = ...
  950. [Rootpath,'/',AnatIDFolder,'/',GroupIDFolder,'/',Filename];
  951. if exist(handles.gui.InputAnatFiles{g}{s}, 'file')
  952. LoadMRI = LoadFTmat(handles.gui.InputAnatFiles{g}{s}, 'BuilderGUI');
  953. if isempty(LoadMRI)
  954. StatusMsg = 'PreprocMRI file found, but contains errors. See ErrorLog.';
  955. else
  956. if isfield(LoadMRI, 'coordsys')
  957. CoordSys = LoadMRI.coordsys;
  958. else
  959. CoordSys = 'Unknown';
  960. end
  961. DimStr = num2str(LoadMRI.dim);
  962. StatusMsg = ['PreprocMRI found. Dim: ',DimStr,'. Coordsys: ',CoordSys];
  963. end
  964. else
  965. StatusMsg = 'Error: PreprocMRI file missing.';
  966. end
  967. handles.gui.StatusAnat{g}{s} = StatusMsg;
  968. end % If AnatID
  969. % Set output handles:
  970. OutputHandles = handles;
  971. %--- Updates input MRI data and GUI panel: ---%
  972. %---------------------------------------------%
  973. function OutputHandles = UpdateInputMRI(InputHandles)
  974. handles = InputHandles;
  975. % Make sure cells initialized:
  976. for g = 1:length(handles.name.GroupID)
  977. for s = 1:length(handles.name.SubjID{g})
  978. try
  979. handles.gui.InputAnatFiles{g}{s};
  980. handles.gui.StatusAnat{g}{s};
  981. catch
  982. handles.gui.InputAnatFiles{g}{s} = [];
  983. handles.gui.StatusAnat{g}{s} = [];
  984. end
  985. end
  986. end
  987. % Update listbox:
  988. GroupIndex = get(handles.ListboxGroupID, 'Value');
  989. if isempty(handles.gui.InputAnatFiles) || isempty(handles.gui.InputAnatFiles{GroupIndex})
  990. set(handles.ListboxInputMRI, 'String', []);
  991. set(handles.ListboxInputMRI, 'Value', 0);
  992. else
  993. if get(handles.CheckboxShowPathMRI, 'Value') == 1
  994. set(handles.ListboxInputMRI, 'String', handles.gui.InputAnatFiles{GroupIndex});
  995. else
  996. set(handles.ListboxInputMRI, 'String', handles.gui.StatusAnat{GroupIndex});
  997. end
  998. end
  999. if ~isempty(handles.gui.InputAnatFiles) && ~isempty(handles.gui.InputAnatFiles{GroupIndex})
  1000. CurrentIndex = get(handles.ListboxInputMRI, 'Value');
  1001. MaxIndex = length(handles.gui.InputAnatFiles{GroupIndex});
  1002. if isempty(CurrentIndex) || CurrentIndex == 0 || CurrentIndex > MaxIndex
  1003. set(handles.ListboxInputMRI, 'Value', MaxIndex);
  1004. set(handles.ListboxSubjID, 'Value', MaxIndex);
  1005. if ~isempty(handles.gui.InputDataFiles)
  1006. set(handles.ListboxInputMEG, 'Value', MaxIndex);
  1007. end
  1008. end
  1009. end
  1010. % Enable/Disable GUI components:
  1011. if isempty(handles.gui.AnatID)
  1012. set(handles.ListboxInputMRI, 'Enable', 'off');
  1013. set(handles.CheckboxShowPathMRI, 'Enable', 'off');
  1014. else
  1015. set(handles.ListboxInputMRI, 'Enable', 'on');
  1016. set(handles.CheckboxShowPathMRI, 'Enable', 'on');
  1017. end
  1018. % Set output handles:
  1019. OutputHandles = handles;
  1020. %--- Load input MRI & GUI panel: ---%
  1021. %-----------------------------------%
  1022. function OutputHandles = LoadInputMRI(InputHandles, LoadedMat)
  1023. handles = InputHandles;
  1024. % Load AnatID (Note: Need to run update fcn after):
  1025. handles.gui.AnatID = LoadedMat.gui.AnatID;
  1026. handles.gui.InputAnatFiles = LoadedMat.gui.InputAnatFiles;
  1027. % Update to get input files and status:
  1028. for g = 1:length(handles.name.GroupID)
  1029. DetectWaitbar = waitbar(0, ...
  1030. ['Scanning input MRI files for: ',handles.name.GroupID{g}], 'Windowstyle', 'modal');
  1031. for s = 1:length(handles.name.SubjID{g})
  1032. waitbar(s/length(handles.name.SubjID{g}), DetectWaitbar);
  1033. handles = DetectInputMRI(handles, g, s);
  1034. end
  1035. delete(DetectWaitbar)
  1036. end
  1037. handles = UpdateInputMRI (handles);
  1038. % Set output handles:
  1039. OutputHandles = handles;
  1040. %--- Reset input MRI & GUI panel: ---%
  1041. %------------------------------------%
  1042. function OutputHandles = ResetInputMRI(InputHandles)
  1043. handles = InputHandles;
  1044. % Reset input MRI:
  1045. handles.gui.AnatID = [];
  1046. handles.gui.InputAnatFiles = [];
  1047. handles.gui.StatusAnat = [];
  1048. % Reset GUI panel:
  1049. set(handles.ListboxInputMRI, 'String', []);
  1050. set(handles.ListboxInputMRI, 'Value', 1);
  1051. set(handles.CheckboxShowPathMRI, 'Value', 0);
  1052. % Set output handles:
  1053. OutputHandles = handles;
  1054. %=======================================================%
  1055. % FUNCTIONS FOR MEG INPUT DISPLAY & FILETYPE SELECTION: %
  1056. %=======================================================%
  1057. %--- Executes on selection change in ListboxInputMEG. ---%
  1058. %------------------------------------------------------------%
  1059. function ListboxInputMEG_Callback(hObject, eventdata, handles)
  1060. if isempty(handles.gui.InputDataFiles)
  1061. return;
  1062. end
  1063. SelectedIndex = get(handles.ListboxInputMEG, 'Value');
  1064. set(handles.ListboxSubjID, 'Value', SelectedIndex);
  1065. if ~isempty(handles.gui.InputAnatFiles)
  1066. set(handles.ListboxInputMRI, 'Value', SelectedIndex);
  1067. end
  1068. %--- Executes on button press in CheckboxShowPathMEG. ---%
  1069. %--------------------------------------------------------%
  1070. function CheckboxShowPathMEG_Callback(hObject, eventdata, handles)
  1071. handles = UpdateInputMEG(handles);
  1072. guidata(hObject, handles);
  1073. %--- Executes on selection change in DropdownMEGdataFiletype. ---%
  1074. %----------------------------------------------------------------%
  1075. function DropdownMEGdataFiletype_Callback(hObject, eventdata, handles)
  1076. handles = ResetCondIDSettings (handles);
  1077. handles.gui.InputDataFiles = []; % Note: Do not use ResetInputMEG here or
  1078. handles.gui.StatusData = []; % filetype will also be reset.
  1079. handles.gui.CheckICAclean = [];
  1080. handles = UpdateInputMEG (handles); % Update dropdown box.
  1081. handles = DetectRootpathFolders (handles);
  1082. handles = DetectCondIDFolders (handles);
  1083. handles = UpdateCondIDSettings (handles);
  1084. % Detect input MEG files & update status:
  1085. for g = 1:length(handles.name.GroupID)
  1086. DetectWaitbar = waitbar(0, ...
  1087. ['Scanning input MEG files for: ',handles.name.GroupID{g}], 'Windowstyle', 'modal');
  1088. for s = 1:length(handles.name.SubjID{g})
  1089. waitbar(s/length(handles.name.SubjID{g}), DetectWaitbar);
  1090. for c = 1:size(handles.gui.AddedCondIDs, 1)
  1091. handles = DetectInputMEG(handles, g, s, c);
  1092. end
  1093. end
  1094. delete(DetectWaitbar)
  1095. end
  1096. handles = UpdateInputMEG(handles);
  1097. % Save handles:
  1098. guidata(hObject, handles);
  1099. %--- Executes on button press in ButtonDetectInputMEG. ---%
  1100. %---------------------------------------------------------%
  1101. function ButtonDetectInputMEG_Callback(hObject, eventdata, handles)
  1102. % Detect input MEG files & update status:
  1103. for g = 1:length(handles.name.GroupID)
  1104. DetectWaitbar = waitbar(0, ...
  1105. ['Scanning input MEG files for: ',handles.name.GroupID{g}], 'Windowstyle', 'modal');
  1106. for s = 1:length(handles.name.SubjID{g})
  1107. waitbar(s/length(handles.name.SubjID{g}), DetectWaitbar);
  1108. for c = 1:size(handles.gui.AddedCondIDs, 1)
  1109. handles = DetectInputMEG(handles, g, s, c);
  1110. end
  1111. end
  1112. delete(DetectWaitbar)
  1113. end
  1114. handles = UpdateInputMEG (handles);
  1115. guidata(hObject, handles);
  1116. %--- Detect input MEG files & status: ---%
  1117. %----------------------------------------%
  1118. function OutputHandles = DetectInputMEG(InputHandles, g, s, c)
  1119. handles = InputHandles;
  1120. % Update input MEG paths and status:
  1121. handles.gui.InputDataFiles{g}{s,c} = [];
  1122. handles.gui.StatusData{g}{s,c} = [];
  1123. handles.gui.CheckICAclean{g}{s,c} = [];
  1124. Rootpath = handles.paths.Rootpath;
  1125. RootpathFolder = handles.gui.AddedCondIDs{c,2};
  1126. GroupIDFolder = ['GroupID_',handles.name.GroupID{g}];
  1127. CondIDFolder = handles.gui.AddedCondIDs{c,1};
  1128. switch handles.gui.MEGdataFiletype
  1129. case 'Fieldtrip'
  1130. MainFolder = [Rootpath,'/',RootpathFolder];
  1131. Filename = [handles.name.SubjID{g}{s},'_PreprocMEG.mat'];
  1132. case 'NIFTI'
  1133. MainFolder = [Rootpath,'/',RootpathFolder,'/NORM_SOURCE_Nifti4D'];
  1134. Filename = [handles.name.SubjID{g}{s},'_Nifti4D.nii'];
  1135. case 'AFNI'
  1136. MainFolder = [Rootpath,'/',RootpathFolder,'/NORM_SOURCE_Afni4D'];
  1137. Filename = [handles.name.SubjID{g}{s},'_Afni4D+tlrc.BRIK'];
  1138. end
  1139. handles.gui.InputDataFiles{g}{s,c} = ...
  1140. [MainFolder,'/',GroupIDFolder,'/',CondIDFolder,'/',Filename];
  1141. CheckICA = []; % For FT files, logs whether ICA cleaning was done on it
  1142. if exist(handles.gui.InputDataFiles{g}{s,c}, 'file')
  1143. if strcmp(handles.gui.MEGdataFiletype, 'Fieldtrip')
  1144. LoadData = LoadFTmat(handles.gui.InputDataFiles{g}{s,c}, 'BuilderGUI');
  1145. if isempty(LoadData)
  1146. StatusMsg = 'PreprocMEG file found, but contains errors. See ErrorLog.';
  1147. else
  1148. NumTrials = size(LoadData.trial, 2);
  1149. StatusMsg = ['PreprocMEG dataset found. Trials: ',num2str(NumTrials)];
  1150. if isfield(LoadData, 'ICAcompRemoved') && ~isempty(LoadData.ICAcompRemoved)
  1151. CheckICA = 1;
  1152. end
  1153. end
  1154. else
  1155. StatusMsg = 'Dataset found.';
  1156. end
  1157. else
  1158. StatusMsg = 'Error: Dataset could not be found. Check paths.';
  1159. end
  1160. handles.gui.StatusData{g}{s,c} = StatusMsg;
  1161. handles.gui.CheckICAclean{g}{s,c} = CheckICA;
  1162. % Set output handles:
  1163. OutputHandles = handles;
  1164. %--- Updates input MEG data & GUI panel: ---%
  1165. %-------------------------------------------%
  1166. function OutputHandles = UpdateInputMEG(InputHandles)
  1167. handles = InputHandles;
  1168. % Update input MEG filetype:
  1169. DropdownOptions = get(handles.DropdownMEGdataFiletype, 'String');
  1170. MEGdataFiletype = DropdownOptions{get(handles.DropdownMEGdataFiletype, 'Value')};
  1171. ViableOptions = {'Fieldtrip', 'NIFTI', 'AFNI'};
  1172. if ismember(MEGdataFiletype, ViableOptions)
  1173. handles.gui.MEGdataFiletype = MEGdataFiletype;
  1174. else
  1175. error('Unrecognized Option') % error-check
  1176. end
  1177. % Make sure cells initialized:
  1178. for g = 1:length(handles.name.GroupID)
  1179. for s = 1:length(handles.name.SubjID{g})
  1180. for c = 1:length(handles.name.CondID)
  1181. try
  1182. handles.gui.InputDataFiles{g}{s,c};
  1183. handles.gui.StatusData{g}{s,c};
  1184. handles.gui.CheckICAclean{g}{s,c};
  1185. catch
  1186. handles.gui.InputDataFiles{g}{s,c} = [];
  1187. handles.gui.StatusData{g}{s,c} = [];
  1188. handles.gui.CheckICAclean{g}{s,c} = [];
  1189. end
  1190. end
  1191. end
  1192. end
  1193. % Update listbox:
  1194. GroupIndex = get(handles.ListboxGroupID, 'Value');
  1195. CondIndex = get(handles.ListboxAddedCondIDs, 'Value');
  1196. if isempty(handles.gui.InputDataFiles) || ...
  1197. isempty(handles.gui.InputDataFiles{GroupIndex}) || isempty(handles.name.CondID)
  1198. set(handles.ListboxInputMEG, 'String', []);
  1199. set(handles.ListboxInputMEG, 'Value', 0);
  1200. else
  1201. if get(handles.CheckboxShowPathMEG, 'Value') == 1
  1202. set(handles.ListboxInputMEG, 'String', ...
  1203. handles.gui.InputDataFiles{GroupIndex}(:,CondIndex));
  1204. else
  1205. set(handles.ListboxInputMEG, 'String', ...
  1206. handles.gui.StatusData{GroupIndex}(:,CondIndex));
  1207. end
  1208. end
  1209. if ~isempty(handles.gui.InputDataFiles) && ...
  1210. ~isempty(handles.gui.InputDataFiles{GroupIndex}) && ~isempty(handles.name.CondID)
  1211. CurrentIndex = get(handles.ListboxInputMEG, 'Value');
  1212. MaxIndex = length(handles.gui.InputDataFiles{GroupIndex}(:,CondIndex));
  1213. if isempty(CurrentIndex) || CurrentIndex == 0 || CurrentIndex > MaxIndex
  1214. set(handles.ListboxInputMEG, 'Value', MaxIndex);
  1215. set(handles.ListboxSubjID, 'Value', MaxIndex);
  1216. if ~isempty(handles.gui.InputAnatFiles)
  1217. set(handles.ListboxInputMRI, 'Value', MaxIndex);
  1218. end
  1219. end
  1220. end
  1221. % Enable/Disable GUI components:
  1222. if isempty(handles.gui.AddedCondIDs)
  1223. set(handles.ListboxInputMEG, 'Enable', 'off');
  1224. set(handles.CheckboxShowPathMEG, 'Enable', 'off');
  1225. else
  1226. set(handles.ListboxInputMEG, 'Enable', 'on');
  1227. set(handles.CheckboxShowPathMEG, 'Enable', 'on');
  1228. end
  1229. % Set output handles:
  1230. OutputHandles = handles;
  1231. %--- Load input MEG data & GUI panel: ---%
  1232. %----------------------------------------%
  1233. function OutputHandles = LoadInputMEG(InputHandles, LoadedMat)
  1234. handles = InputHandles;
  1235. % Load input MEG settings:
  1236. handles.gui.MEGdataFiletype = LoadedMat.gui.MEGdataFiletype;
  1237. handles.gui.InputDataFiles = LoadedMat.gui.InputDataFiles;
  1238. handles.gui.AddedCondIDs = LoadedMat.gui.AddedCondIDs;
  1239. handles.name.CondID = LoadedMat.name.CondID;
  1240. % Load GUI panel:
  1241. DropdownOptions = get(handles.DropdownMEGdataFiletype, 'String');
  1242. DropdownValue = find(strcmp(DropdownOptions, handles.gui.MEGdataFiletype));
  1243. set(handles.DropdownMEGdataFiletype, 'Value', DropdownValue);
  1244. if DropdownValue == 0
  1245. error('Option does not exist in dropdown list.') % error-check
  1246. end
  1247. set(handles.ListboxAddedCondIDs, 'String', handles.gui.AddedCondIDs(:,3));
  1248. set(handles.ListboxAddedCondIDs, 'Value', 1);
  1249. % Update to get input files and status:
  1250. for g = 1:length(handles.name.GroupID)
  1251. DetectWaitbar = waitbar(0, ...
  1252. ['Scanning input MEG files for: ',handles.name.GroupID{g}], 'Windowstyle', 'modal');
  1253. for s = 1:length(handles.name.SubjID{g})
  1254. waitbar(s/length(handles.name.SubjID{g}), DetectWaitbar);
  1255. for c = 1:size(handles.gui.AddedCondIDs, 1)
  1256. handles = DetectInputMEG(handles, g, s, c);
  1257. end
  1258. end
  1259. delete(DetectWaitbar)
  1260. end
  1261. handles = UpdateInputMEG(handles);
  1262. % Set output handles:
  1263. OutputHandles = handles;
  1264. %--- Reset input MEG data & GUI panel: ---%
  1265. %-----------------------------------------%
  1266. function OutputHandles = ResetInputMEG(InputHandles)
  1267. handles = InputHandles;
  1268. % Reset input MEG:
  1269. handles.gui.MEGdataFiletype = 'Fieldtrip';
  1270. handles.gui.InputDataFiles = [];
  1271. handles.gui.StatusData = [];
  1272. handles.gui.CheckICAclean = [];
  1273. handles.gui.AddedCondIDs = [];
  1274. handles.name.CondID = [];
  1275. % Reset GUI panel:
  1276. set(handles.DropdownMEGdataFiletype, 'Value', 1);
  1277. set(handles.CheckboxShowPathMEG, 'Value', 0);
  1278. set(handles.ListboxInputMEG, 'String', []);
  1279. set(handles.ListboxInputMEG, 'Value', 1);
  1280. set(handles.ListboxAddedCondIDs, 'String', []);
  1281. set(handles.ListboxAddedCondIDs, 'Value', 1);
  1282. % Set output handles:
  1283. OutputHandles = handles;
  1284. %=======================================================%
  1285. % FUNCTIONS FOR DETECTING ROOTPATH FOLDERS AND CONDIDs: %
  1286. %=======================================================%
  1287. %--- Executes on selection change in ListboxRootpathFolders. ----%
  1288. %----------------------------------------------------------------%
  1289. function ListboxRootpathFolders_Callback(hObject, eventdata, handles)
  1290. handles = DetectCondIDFolders(handles);
  1291. guidata(hObject, handles);
  1292. %--- Executes on selection change in ListboxDetectedCondIDs. ---%
  1293. %---------------------------------------------------------------%
  1294. function ListboxDetectedCondIDs_Callback(hObject, eventdata, handles)
  1295. guidata(hObject, handles);
  1296. %--- Detect DataID or AnalysisID folders in Rootpath: ---%
  1297. %--------------------------------------------------------%
  1298. function OutputHandles = DetectRootpathFolders(InputHandles)
  1299. handles = InputHandles;
  1300. % Get DataID / AnalysisID folders in current rootpath:
  1301. if strcmp(handles.gui.MEGdataFiletype, 'Fieldtrip')
  1302. DetectedFolders = dir([handles.paths.Rootpath,'/DataID_*']);
  1303. DetectedFolders = [DetectedFolders; dir([handles.paths.Rootpath,'/DataID-ICAclean_*'])];
  1304. else
  1305. DetectedFolders = dir([handles.paths.Rootpath,'/AnalysisID_*']);
  1306. end
  1307. RemoveIndex = [];
  1308. for d = 1:length(DetectedFolders)
  1309. if DetectedFolders(d).isdir ~= 1
  1310. RemoveIndex = [RemoveIndex, d]; % Get unwanted indices
  1311. end
  1312. end
  1313. DetectedFolders(RemoveIndex) = [];
  1314. % Set detected rootpath folders:
  1315. DetectedFolders = {DetectedFolders.name};
  1316. handles.gui.RootpathFolders = DetectedFolders;
  1317. % Update listbox:
  1318. set(handles.ListboxRootpathFolders, 'String', handles.gui.RootpathFolders);
  1319. CurrentIndex = get(handles.ListboxRootpathFolders, 'Value');
  1320. MaxIndex = length(handles.gui.RootpathFolders);
  1321. if isempty(CurrentIndex) || CurrentIndex == 0 || CurrentIndex > MaxIndex
  1322. set(handles.ListboxRootpathFolders, 'Value', MaxIndex);
  1323. end
  1324. % Set as output handles:
  1325. OutputHandles = handles;
  1326. %--- Detect CondID folders for selection: ---%
  1327. %--------------------------------------------%
  1328. function OutputHandles = DetectCondIDFolders(InputHandles)
  1329. handles = InputHandles;
  1330. % Get CondID folders in selected RootpathFolder:
  1331. FolderIndex = get(handles.ListboxRootpathFolders, 'Value');
  1332. if FolderIndex == 0 || isempty(FolderIndex)
  1333. OutputHandles = handles;
  1334. return;
  1335. end
  1336. RootpathFolder = handles.gui.RootpathFolders{FolderIndex};
  1337. Rootpath = handles.paths.Rootpath;
  1338. % Set search path:
  1339. switch handles.gui.MEGdataFiletype
  1340. case 'Fieldtrip'
  1341. SearchPath = [Rootpath,'/',RootpathFolder];
  1342. case 'NIFTI'
  1343. SearchPath = [Rootpath,'/',RootpathFolder,'/NORM_SOURCE_Nifti4D'];
  1344. case 'AFNI'
  1345. SearchPath = [Rootpath,'/',RootpathFolder,'/NORM_SOURCE_Afni4D'];
  1346. end
  1347. % Get GroupID folders in RootpathFolder to search within:
  1348. GroupFolders = dir([SearchPath,'/GroupID_*']);
  1349. RemoveIndex = [];
  1350. for d = 1:length(GroupFolders)
  1351. if GroupFolders(d).isdir ~= 1 || ismember(GroupFolders(d).name, {'.', '..'})
  1352. RemoveIndex = [RemoveIndex, d];
  1353. end
  1354. end
  1355. GroupFolders(RemoveIndex) = [];
  1356. GroupFolders = {GroupFolders.name};
  1357. % Search GroupID folders for available CondIDs:
  1358. CondFolders = [];
  1359. for g = 1:length(GroupFolders)
  1360. SearchGroup = dir([SearchPath,'/',GroupFolders{g},'/*']);
  1361. CondFolders = [CondFolders; (SearchGroup)];
  1362. end
  1363. RemoveIndex = [];
  1364. for d = 1:length(CondFolders)
  1365. if CondFolders(d).isdir ~= 1 || ismember(CondFolders(d).name, {'.', '..'})
  1366. RemoveIndex = [RemoveIndex, d];
  1367. end
  1368. end
  1369. CondFolders(RemoveIndex) = [];
  1370. % Set detected CondID folders:
  1371. if ~isempty(CondFolders)
  1372. CondFolders = {CondFolders.name};
  1373. CondFolders = unique(CondFolders);
  1374. end
  1375. if isempty(CondFolders)
  1376. handles.gui.DetectedCondIDs = [];
  1377. else
  1378. handles.gui.DetectedCondIDs = CondFolders;
  1379. end
  1380. % Update listbox:
  1381. set(handles.ListboxDetectedCondIDs, 'String', handles.gui.DetectedCondIDs);
  1382. CurrentIndex = get(handles.ListboxDetectedCondIDs, 'Value');
  1383. MaxIndex = length(handles.gui.DetectedCondIDs);
  1384. if isempty(CurrentIndex) || CurrentIndex == 0 || CurrentIndex > MaxIndex
  1385. set(handles.ListboxDetectedCondIDs, 'Value', MaxIndex);
  1386. end
  1387. % Set as output handles:
  1388. OutputHandles = handles;
  1389. %==================================================%
  1390. % FUNCTIONS FOR SELECTING CONDITIONS AND DATASETS: %
  1391. %==================================================%
  1392. %--- Executes on selection change in ListboxAddedCondIDs. ---%
  1393. %------------------------------------------------------------%
  1394. function ListboxAddedCondIDs_Callback(hObject, eventdata, handles)
  1395. handles = UpdateInputMEG(handles);
  1396. guidata(hObject, handles);
  1397. %--- Executes on button press in ButtonAddCondID. ---%
  1398. %----------------------------------------------------%
  1399. function ButtonAddCondID_Callback(hObject, eventdata, handles)
  1400. if isempty(handles.paths.Rootpath)
  1401. msgbox('Warning: Select root directory first.', 'Warning:');
  1402. return;
  1403. end
  1404. if isempty(handles.name.AnalysisID) || isempty(handles.paths.AnalysisID)
  1405. msgbox('Warning: Create or load AnalysisID first.', 'Warning:');
  1406. return;
  1407. end
  1408. if isempty(handles.name.GroupID)
  1409. msgbox('Warning: Create or load a GroupID first.', 'Warning:');
  1410. return;
  1411. end
  1412. if isempty(handles.gui.DetectedCondIDs)
  1413. return;
  1414. end
  1415. % Get selected RootpathFolder and DetectedCondID:
  1416. FolderIndex = get(handles.ListboxRootpathFolders, 'Value');
  1417. RootpathFolder = handles.gui.RootpathFolders{FolderIndex};
  1418. CondIndex = get(handles.ListboxDetectedCondIDs, 'Value');
  1419. TargetCondID = handles.gui.DetectedCondIDs{CondIndex};
  1420. FolderCondString = [RootpathFolder,': ',TargetCondID];
  1421. if ismember(TargetCondID, handles.name.CondID)
  1422. msgbox('Error: CondID with the same name has already been added.', 'Error:')
  1423. return;
  1424. end
  1425. % Add CondID folder:
  1426. handles.name.CondID = [handles.name.CondID; cellstr(TargetCondID)];
  1427. NewCondIndex = length(handles.name.CondID);
  1428. handles.gui.AddedCondIDs{NewCondIndex,1} = TargetCondID;
  1429. handles.gui.AddedCondIDs{NewCondIndex,2} = RootpathFolder;
  1430. handles.gui.AddedCondIDs{NewCondIndex,3} = FolderCondString;
  1431. % Update settings & GUI:
  1432. handles = UpdateCondIDSettings (handles);
  1433. for g = 1:length(handles.name.GroupID)
  1434. DetectWaitbar = waitbar(0, ...
  1435. ['Scanning input MEG files for: ',handles.name.GroupID{g}], 'Windowstyle', 'modal');
  1436. for s = 1:length(handles.name.SubjID{g})
  1437. waitbar(s/length(handles.name.SubjID{g}), DetectWaitbar);
  1438. for c = NewCondIndex % Only update for new cond index
  1439. handles = DetectInputMEG(handles, g, s, c);
  1440. end
  1441. end
  1442. delete(DetectWaitbar)
  1443. end
  1444. handles = UpdateInputMEG(handles);
  1445. % Save handles:
  1446. guidata(hObject, handles);
  1447. %--- Executes on button press in ButtonRmvCondID. ---%
  1448. %----------------------------------------------------%
  1449. function ButtonRmvCondID_Callback(hObject, eventdata, handles)
  1450. if isempty(handles.name.CondID)
  1451. return;
  1452. end
  1453. SelectedIndex = get(handles.ListboxAddedCondIDs, 'Value');
  1454. handles.name.CondID (SelectedIndex) = [];
  1455. handles.gui.AddedCondIDs (SelectedIndex,:) = [];
  1456. for g = 1:length(handles.name.GroupID)
  1457. handles.gui.InputDataFiles{g}(:,SelectedIndex) = [];
  1458. handles.gui.StatusData{g}(:,SelectedIndex) = [];
  1459. handles.gui.CheckICAclean{g}(:,SelectedIndex) = [];
  1460. end
  1461. % Update settings & GUI:
  1462. handles = UpdateCondIDSettings (handles);
  1463. handles = UpdateInputMEG (handles);
  1464. % Save handles:
  1465. guidata(hObject, handles);
  1466. %--- Updates CondID settings & GUI panel: ---%
  1467. %--------------------------------------------%
  1468. function OutputHandles = UpdateCondIDSettings(InputHandles)
  1469. handles = InputHandles;
  1470. % Update listbox:
  1471. if isempty(handles.gui.AddedCondIDs)
  1472. set(handles.ListboxAddedCondIDs, 'String', []);
  1473. else
  1474. set(handles.ListboxAddedCondIDs, 'String', handles.gui.AddedCondIDs(:,3));
  1475. end
  1476. CurrentIndex = get(handles.ListboxAddedCondIDs, 'Value');
  1477. MaxIndex = size(handles.gui.AddedCondIDs, 1);
  1478. if isempty(CurrentIndex) || CurrentIndex == 0 || CurrentIndex > MaxIndex
  1479. set(handles.ListboxAddedCondIDs, 'Value', MaxIndex);
  1480. end
  1481. % Set output handles:
  1482. OutputHandles = handles;
  1483. %--- Load CondID settings & GUI panel: ---%
  1484. %-----------------------------------------%
  1485. function OutputHandles = LoadCondIDSettings(InputHandles, LoadedMat)
  1486. handles = InputHandles;
  1487. % Load CondID settings:
  1488. handles.name.CondID = LoadedMat.name.CondID;
  1489. handles.gui.AddedCondIDs = LoadedMat.gui.AddedCondIDs;
  1490. % Reset GUI panel:
  1491. set(handles.ListboxAddedCondIDs, 'String', handles.gui.AddedCondIDs(:,3));
  1492. set(handles.ListboxAddedCondIDs, 'Value', 1);
  1493. % Set output handles:
  1494. OutputHandles = handles;
  1495. %--- Reset CondID settings & GUI panel: ---%
  1496. %------------------------------------------%
  1497. function OutputHandles = ResetCondIDSettings(InputHandles)
  1498. handles = InputHandles;
  1499. % Reset CondID settings:
  1500. handles.name.CondID = [];
  1501. handles.gui.AddedCondIDs = [];
  1502. handles.gui.CommonFilterCondID = [];
  1503. handles.gui.ControlCondID = [];
  1504. handles.gui.DetectedCondIDs = [];
  1505. handles.gui.RootpathFolders = [];
  1506. % Reset GUI panel:
  1507. set(handles.ListboxAddedCondIDs, 'String', []);
  1508. set(handles.ListboxAddedCondIDs, 'Value', 1);
  1509. set(handles.CheckboxEstNoiseCommonFilt, 'Value', 0);
  1510. set(handles.TextboxCommonFiltControlCond, 'String', 'None Selected');
  1511. set(handles.ListboxDetectedCondIDs, 'String', []);
  1512. set(handles.ListboxDetectedCondIDs, 'Value', 1);
  1513. set(handles.ListboxRootpathFolders, 'String', []);
  1514. set(handles.ListboxRootpathFolders, 'Value', 1);
  1515. % Set output handles:
  1516. OutputHandles = handles;
  1517. %=======================================%
  1518. % FUNCTIONS FOR ANALYSIS TIME SETTINGS: %
  1519. %=======================================%
  1520. %--- Textbox for user to enter analysis time start: ---%
  1521. %------------------------------------------------------%
  1522. function TextboxTimeStart_Callback(hObject, eventdata, handles)
  1523. StartTime = str2num(get(handles.TextboxTimeStart, 'String'));
  1524. EndTime = str2num(get(handles.TextboxTimeEnd, 'String'));
  1525. if isempty(StartTime)
  1526. msgbox('Error: Start time must be specified.', 'Error:');
  1527. return;
  1528. end
  1529. if StartTime > EndTime
  1530. msgbox('Error: Start time cannot be greater than end time.', 'Error:');
  1531. set(handles.TextboxTimeStart, 'String', []);
  1532. return;
  1533. end
  1534. % Adjust custom CovCsd start time:
  1535. set(handles.TextboxCovCsdTimeStart, 'String', num2str(StartTime, '%1.3f'));
  1536. % Save handles:
  1537. handles = UpdateTimeSettings(handles);
  1538. guidata(hObject, handles);
  1539. %--- Textbox for user to enter analysis time end: ---%
  1540. %----------------------------------------------------%
  1541. function TextboxTimeEnd_Callback(hObject, eventdata, handles)
  1542. StartTime = str2num(get(handles.TextboxTimeStart, 'String'));
  1543. EndTime = str2num(get(handles.TextboxTimeEnd, 'String'));
  1544. if isempty(EndTime)
  1545. msgbox('Error: End time must be specified.', 'Error:');
  1546. return;
  1547. end
  1548. if EndTime < StartTime
  1549. msgbox('Error: End time cannot be less than start time.', 'Error:');
  1550. set(handles.TextboxTimeEnd, 'String', []);
  1551. return;
  1552. end
  1553. % Adjust custom CovCsd end time:
  1554. set(handles.TextboxCovCsdTimeEnd, 'String', num2str(EndTime, '%1.3f'));
  1555. % Save handles:
  1556. handles = UpdateTimeSettings(handles);
  1557. guidata(hObject, handles);
  1558. %--- Textbox for user to enter sliding window-size: ---%
  1559. %------------------------------------------------------%
  1560. function TextboxWindowSize_Callback(hObject, eventdata, handles)
  1561. StartTime = str2num(get(handles.TextboxTimeStart, 'String'));
  1562. EndTime = str2num(get(handles.TextboxTimeEnd, 'String'));
  1563. WindowSize = str2num(get(handles.TextboxWindowSize, 'String'));
  1564. if isempty(WindowSize)
  1565. msgbox('Error: Window size must be specified.', 'Error:');
  1566. return;
  1567. end
  1568. if WindowSize > (EndTime - StartTime)
  1569. msgbox('Error: Window size cannot be greater than epoch length.', 'Error:');
  1570. set(handles.TextboxWindowSize, 'String', []);
  1571. return;
  1572. end
  1573. handles = UpdateTimeSettings(handles);
  1574. guidata(hObject, handles);
  1575. %--- Textbox for user to enter time-step: ---%
  1576. %--------------------------------------------%
  1577. function TextboxTimeStep_Callback(hObject, eventdata, handles)
  1578. TimeStep = str2num(get(handles.TextboxTimeStep, 'String'));
  1579. if isempty(TimeStep)
  1580. msgbox('Error: Time step must be specified.', 'Error:');
  1581. set(handles.TextboxTimeStep, 'String', num2str(0.020, '%1.3f'));
  1582. return;
  1583. end
  1584. if TimeStep == 0
  1585. msgbox('Error: Time step cannot be 0.', 'Error:');
  1586. set(handles.TextboxTimeStep, 'String', num2str(0.020, '%1.3f'));
  1587. return;
  1588. end
  1589. handles = UpdateTimeSettings(handles);
  1590. guidata(hObject, handles);
  1591. %--- Updates analysis time settings & GUI panel: ---%
  1592. %---------------------------------------------------%
  1593. function OutputHandles = UpdateTimeSettings(InputHandles)
  1594. handles = InputHandles;
  1595. time = handles.time;
  1596. % Read GUI to update settings:
  1597. time.Start = str2num(get(handles.TextboxTimeStart, 'String'));
  1598. time.End = str2num(get(handles.TextboxTimeEnd, 'String'));
  1599. time.WindowSize = str2num(get(handles.TextboxWindowSize, 'String'));
  1600. time.Step = str2num(get(handles.TextboxTimeStep, 'String'));
  1601. % Set starting window & index:
  1602. WindowStart = time.Start;
  1603. WindowEnd = time.Start + time.WindowSize;
  1604. t = 1;
  1605. % Set time window data:
  1606. time.Windows = [];
  1607. while WindowEnd < time.End | abs(WindowEnd - time.End) < 0.001
  1608. time.Windows(t,1) = WindowStart;
  1609. time.Windows(t,2) = WindowEnd;
  1610. WindowStart = WindowStart + time.Step;
  1611. WindowEnd = WindowEnd + time.Step;
  1612. t = t + 1;
  1613. WindowStart = round(WindowStart*10000)/10000;
  1614. WindowEnd = round(WindowEnd*10000)/10000;
  1615. end
  1616. % Create strings:
  1617. time.str.StartEnd = [];
  1618. time.str.Windows = [];
  1619. if ~isempty(time.Start) && ~isempty(time.End)
  1620. time.str.StartEnd = ...
  1621. [num2str(time.Start, '%1.3f'),'s_',num2str(time.End, '%1.3f'),'s'];
  1622. end
  1623. for t = 1:size(time.Windows, 1)
  1624. time.str.Windows{t,1} = num2str(time.Windows(t,1), '%1.3f');
  1625. time.str.Windows{t,2} = num2str(time.Windows(t,2), '%1.3f');
  1626. time.str.Windows{t,3} = ...
  1627. [time.str.Windows{t,1},'s_',time.str.Windows{t,2},'s'];
  1628. end
  1629. % Set output handles:
  1630. handles.time = time;
  1631. OutputHandles = handles;
  1632. %--- Load analysis time settings & GUI panel: ---%
  1633. %------------------------------------------------%
  1634. function OutputHandles = LoadTimeSettings(InputHandles, LoadedMat)
  1635. handles = InputHandles;
  1636. time = handles.time;
  1637. % Load analysis time settings:
  1638. time.Start = LoadedMat.time.Start;
  1639. time.End = LoadedMat.time.End;
  1640. time.WindowSize = LoadedMat.time.WindowSize;
  1641. time.Step = LoadedMat.time.Step;
  1642. % Load analysis GUI panel:
  1643. set(handles.TextboxTimeStart, 'String', num2str(time.Start, '%1.3f'));
  1644. set(handles.TextboxTimeEnd, 'String', num2str(time.End, '%1.3f'));
  1645. set(handles.TextboxWindowSize, 'String', num2str(time.WindowSize, '%1.3f'));
  1646. set(handles.TextboxTimeStep, 'String', num2str(time.Step, '%1.3f'));
  1647. % Update to recompile time windows:
  1648. handles = UpdateTimeSettings(handles);
  1649. % Set output handles:
  1650. handles.time = time;
  1651. OutputHandles = handles;
  1652. %--- Reset analysis time settings & GUI panel: ---%
  1653. %-------------------------------------------------%
  1654. function OutputHandles = ResetTimeSettings(InputHandles)
  1655. handles = InputHandles;
  1656. time = handles.time;
  1657. % Reset analysis time settings:
  1658. time.Start = 0.000;
  1659. time.End = 1.000;
  1660. time.WindowSize = 0.040;
  1661. time.Step = 0.020;
  1662. % Reset GUI panel:
  1663. set(handles.TextboxTimeStart, 'String', num2str(0.000, '%1.3f'));
  1664. set(handles.TextboxTimeEnd, 'String', num2str(1.000, '%1.3f'));
  1665. set(handles.TextboxWindowSize, 'String', num2str(0.040, '%1.3f'));
  1666. set(handles.TextboxTimeStep, 'String', num2str(0.020, '%1.3f'));
  1667. % Update to recompile time windows:
  1668. handles = UpdateTimeSettings(handles);
  1669. % Set output handles:
  1670. handles.time = time;
  1671. OutputHandles = handles;
  1672. %===============================================%
  1673. % FUNCTIONS FOR HEADMODEL & LEADFIELD SETTINGS: %
  1674. %===============================================%
  1675. %--- GUI functions for headmodel and leadfield: ---%
  1676. %--------------------------------------------------%
  1677. function DropdownHdmMethod_Callback(hObject, eventdata, handles)
  1678. handles = UpdateHdmLeadSettings(handles);
  1679. guidata(hObject, handles);
  1680. function TextboxLeadfieldRes_Callback(hObject, eventdata, handles)
  1681. if isempty(get(handles.TextboxLeadfieldRes, 'String'));
  1682. msgbox('Note: Leadfield resolution not specified. Default set to 5mm.');
  1683. set(handles.TextboxLeadfieldRes, 'String', num2str(5));
  1684. end
  1685. handles = UpdateHdmLeadSettings(handles);
  1686. guidata(hObject, handles);
  1687. %--- Executes on button press in ButtonTimelockFreqAdvSettings. ---%
  1688. %------------------------------------------------------------------%
  1689. function ButtonHdmAdvSettings_Callback(hObject, eventdata, handles)
  1690. if isempty(handles.paths.Rootpath)
  1691. msgbox('Warning: Select root directory first.', 'Warning:');
  1692. return;
  1693. end
  1694. if isempty(handles.name.AnalysisID) || isempty(handles.paths.AnalysisID)
  1695. msgbox('Warning: Create or load AnalysisID first.', 'Warning:');
  1696. return;
  1697. end
  1698. %** Opens settings .m file: Upgrade to sub-GUI later (Make it modal).
  1699. % - Can run child GUI, then call: uiwait(gcf) OR waitfor(childGUI)
  1700. % - Have updatefcns read adv.settings output to update settings accordingly.
  1701. open([handles.paths.AnalysisID,'/SETTINGS/Settings_SegHdmLeadfield.m']);
  1702. %--- Updates headmodel & leadfield settings & GUI panel: ---%
  1703. %-----------------------------------------------------------%
  1704. function OutputHandles = UpdateHdmLeadSettings(InputHandles)
  1705. handles = InputHandles;
  1706. FTcfg = handles.FTcfg;
  1707. % Read GUI to update settings:
  1708. DropdownOptions = get(handles.DropdownHdmMethod, 'String');
  1709. HdmMethod = DropdownOptions{get(handles.DropdownHdmMethod, 'Value')};
  1710. ViableOptions = {'singleshell'; 'localspheres'; 'singlesphere'; 'infinite'};
  1711. if ismember(HdmMethod, ViableOptions)
  1712. FTcfg.Hdm.method = HdmMethod;
  1713. else
  1714. error('Unrecognized Option'); % error-check
  1715. end
  1716. LeadfieldRes = str2num(get(handles.TextboxLeadfieldRes, 'String'));
  1717. FTcfg.Lead.grid.resolution = LeadfieldRes;
  1718. % Set output handles:
  1719. handles.FTcfg = FTcfg;
  1720. OutputHandles = handles;
  1721. %--- Load headmodel & leadfield settings & GUI panel: ---%
  1722. %--------------------------------------------------------%
  1723. function OutputHandles = LoadHdmLeadSettings(InputHandles, LoadedMat)
  1724. handles = InputHandles;
  1725. FTcfg = handles.FTcfg;
  1726. % Load settings:
  1727. FTcfg.Hdm.method = LoadedMat.FTcfg.Hdm.method;
  1728. FTcfg.Lead.grid.resolution = LoadedMat.FTcfg.Lead.grid.resolution;
  1729. % Load GUI panel:
  1730. DropdownOptions = get(handles.DropdownHdmMethod, 'String');
  1731. DropdownValue = find(strcmp(DropdownOptions, FTcfg.Hdm.method));
  1732. set(handles.DropdownHdmMethod, 'Value', DropdownValue);
  1733. if isempty(DropdownValue)
  1734. error('Option does not exist in dropdown list.'); % error-check
  1735. end
  1736. set(handles.TextboxLeadfieldRes, 'String', num2str(FTcfg.Lead.grid.resolution));
  1737. % Set output handles:
  1738. handles.FTcfg = FTcfg;
  1739. OutputHandles = handles;
  1740. %--- Reset headmodel & leadfield settings & GUI panel: ---%
  1741. %---------------------------------------------------------%
  1742. function OutputHandles = ResetHdmLeadSettings(InputHandles)
  1743. handles = InputHandles;
  1744. FTcfg = handles.FTcfg;
  1745. % Reset settings:
  1746. FTcfg.Hdm.method = 'singleshell';
  1747. FTcfg.Lead.grid.resolution = 5;
  1748. % Reset GUI panel:
  1749. set(handles.DropdownHdmMethod, 'Value', 1);
  1750. set(handles.TextboxLeadfieldRes, 'String', num2str(5));
  1751. % Set output handles:
  1752. handles.FTcfg = FTcfg;
  1753. OutputHandles = handles;
  1754. %============================================%
  1755. % FUNCTIONS FOR TIME/FREQ ANALYSIS SETTINGS: %
  1756. %============================================%
  1757. %--- GUI functions for COV & CSD settings: ---%
  1758. %---------------------------------------------%
  1759. function CheckboxCovDemean_Callback(hObject, eventdata, handles)
  1760. handles = UpdateTimeFreqSettings(handles);
  1761. guidata(hObject, handles);
  1762. function DropdownCovCsdTime_Callback(hObject, eventdata, handles)
  1763. handles = UpdateTimeFreqSettings(handles);
  1764. guidata(hObject, handles);
  1765. % User enters custom start-time for COV/CSD here:
  1766. function TextboxCovCsdTimeStart_Callback(hObject, eventdata, handles)
  1767. TimeStart = str2num(get(handles.TextboxCovCsdTimeStart, 'String'));
  1768. TimeEnd = str2num(get(handles.TextboxCovCsdTimeEnd, 'String'));
  1769. if isempty(TimeStart)
  1770. msgbox('Error: Custom COV/CSD start time not specified.', 'Error:');
  1771. return
  1772. end
  1773. if TimeStart > TimeEnd
  1774. msgbox('Error: COV/CSD start time cannot be greater than end time.', 'Error:');
  1775. set(handles.TextboxCovCsdTimeStart, 'String', []);
  1776. return;
  1777. end
  1778. handles = UpdateTimeFreqSettings(handles);
  1779. guidata(hObject, handles);
  1780. % User enters custom end-time for COV/CSD here:
  1781. function TextboxCovCsdTimeEnd_Callback(hObject, eventdata, handles)
  1782. TimeStart = str2num(get(handles.TextboxCovCsdTimeStart, 'String'));
  1783. TimeEnd = str2num(get(handles.TextboxCovCsdTimeEnd, 'String'));
  1784. if isempty(TimeEnd)
  1785. msgbox('Error: Custom COV/CSD end time not specified.', 'Error:');
  1786. return;
  1787. end
  1788. if TimeEnd < TimeStart
  1789. msgbox('Error: COV/CSD end time cannot be less than start time.', 'Error:');
  1790. set(handles.TextboxCovCsdTimeEnd, 'String', []);
  1791. return;
  1792. end
  1793. handles = UpdateTimeFreqSettings(handles);
  1794. guidata(hObject, handles);
  1795. %--- GUI functions for frequency analysis settings: ---%
  1796. %------------------------------------------------------%
  1797. % Executes on selection change in DropdownFreqMethod.
  1798. function DropdownFreqMethod_Callback(hObject, eventdata, handles)
  1799. DropdownOptions = get(handles.DropdownFreqMethod, 'String');
  1800. FreqMethod = DropdownOptions{get(handles.DropdownFreqMethod, 'Value')};
  1801. FreqRes = str2num(get(handles.TextboxFreqRes, 'String'));
  1802. if strcmp(FreqMethod, 'mtmconvol: Fixed Time Win.')
  1803. message = {'WARNING:'; '';
  1804. 'For "mtmconvol" with fixed time-windows:';
  1805. 'Frequency resolution determines the size of the fixed time-window.'; '';
  1806. ['Current freq. resolution: ',num2str(FreqRes),'Hz'];
  1807. ['Fixed time-window size: ',num2str(1 / FreqRes),'s']};
  1808. msgbox(message, 'WARNING:');
  1809. end
  1810. handles = UpdateTimeFreqSettings(handles);
  1811. guidata(hObject, handles);
  1812. %--- User enters frequency resolution for freq. analysis here: ---%
  1813. %-----------------------------------------------------------------%
  1814. function TextboxFreqRes_Callback(hObject, eventdata, handles)
  1815. FreqStart = str2num(get(handles.TextboxFreqFoiStart, 'String'));
  1816. FreqEnd = str2num(get(handles.TextboxFreqFoiEnd, 'String'));
  1817. FreqRes = str2num(get(handles.TextboxFreqRes, 'String'));
  1818. if isempty(FreqRes)
  1819. msgbox('Error: Frequency resolution must be specified.', 'Error:');
  1820. return;
  1821. end
  1822. DropdownOptions = get(handles.DropdownFreqMethod, 'String');
  1823. FreqMethod = DropdownOptions{get(handles.DropdownFreqMethod, 'Value')};
  1824. if strcmp(FreqMethod, 'mtmconvol: Fixed Time Win.')
  1825. TotalAnalysisTime = handles.time.End - handles.time.Start;
  1826. FixedTimeWinSize = 1 / FreqRes;
  1827. if FixedTimeWinSize > TotalAnalysisTime
  1828. message = {'ERROR:'; '';
  1829. 'The size of the fixed time-window for frequency analysis is larger';
  1830. ['than the current total analysis time (',num2str(TotalAnalysisTime),' s).']; '';
  1831. 'For the method "mtmconvol" with fixed time-windows:';
  1832. 'Frequency resolution determines the size of the fixed time-window.'; '';
  1833. ['Current freq. resolution: ',num2str(FreqRes),'Hz'];
  1834. ['Fixed time-window size: ',num2str(1 / FreqRes),'s']; '';
  1835. 'Select a larger FreqRes value, or increase length of analysis window.'; ''};
  1836. msgbox(message, 'ERROR:');
  1837. set(handles.TextboxFreqRes, 'String', []);
  1838. return;
  1839. end
  1840. end
  1841. handles = UpdateTimeFreqSettings(handles);
  1842. guidata(hObject, handles);
  1843. %--- User enters start frequency for frequency analysis here: ---%
  1844. %----------------------------------------------------------------%
  1845. function TextboxFreqFoiStart_Callback(hObject, eventdata, handles)
  1846. FreqStart = str2num(get(handles.TextboxFreqFoiStart, 'String'));
  1847. FreqEnd = str2num(get(handles.TextboxFreqFoiEnd, 'String'));
  1848. if isempty(FreqStart)
  1849. msgbox('Error: Start frequency must be specified.', 'Error:');
  1850. return;
  1851. end
  1852. if FreqStart > FreqEnd
  1853. msgbox('Error: Start frequency cannot be greater than end frequency.', 'Error:');
  1854. set(handles.TextboxFreqFoiStart, 'String', []);
  1855. return;
  1856. end
  1857. handles = UpdateTimeFreqSettings(handles);
  1858. guidata(hObject, handles);
  1859. %--- User enters end frequency for frequency analysis here: ---%
  1860. %--------------------------------------------------------------%
  1861. function TextboxFreqFoiEnd_Callback(hObject, eventdata, handles)
  1862. FreqStart = str2num(get(handles.TextboxFreqFoiStart, 'String'));
  1863. FreqEnd = str2num(get(handles.TextboxFreqFoiEnd, 'String'));
  1864. if isempty(FreqEnd)
  1865. msgbox('Error: End frequency must be specified.', 'Error:');
  1866. return;
  1867. end
  1868. if FreqEnd < FreqStart
  1869. msgbox('Error: End frequency cannot be less than start frequency.', 'Error:');
  1870. set(handles.TextboxFreqFoiEnd, 'String', []);
  1871. return;
  1872. end
  1873. handles = UpdateTimeFreqSettings(handles);
  1874. guidata(hObject, handles);
  1875. %--- Executes on button press in ButtonTimelockFreqAdvSettings. ---%
  1876. %------------------------------------------------------------------%
  1877. function ButtonTimelockFreqAdvSettings_Callback(hObject, eventdata, handles)
  1878. if isempty(handles.paths.Rootpath)
  1879. msgbox('Warning: Please select root directory first.', 'Warning:');
  1880. return;
  1881. end
  1882. if isempty(handles.name.AnalysisID) || isempty(handles.paths.AnalysisID)
  1883. msgbox('Warning: Create or load AnalysisID first.', 'Warning:');
  1884. return;
  1885. end
  1886. %** Opens settings .m file: Upgrade to sub-GUI later (Make it modal).
  1887. % - Can run child GUI, then call: uiwait(gcf) OR waitfor(childGUI)
  1888. % - Have updatefcns read adv.settings output to update settings accordingly.
  1889. open([handles.paths.AnalysisID,'/SETTINGS/Settings_TimelockFreqAnalysis.m']);
  1890. %--- Updates time/freq analysis settings: ---%
  1891. %--------------------------------------------%
  1892. function OutputHandles = UpdateTimeFreqSettings(InputHandles)
  1893. handles = InputHandles;
  1894. FTcfg = handles.FTcfg;
  1895. PipeSettings = handles.PipeSettings;
  1896. % Read GUI to update COV & CSD settings:
  1897. if get(handles.CheckboxCovDemean, 'Value') == 1
  1898. FTcfg.Timelock.removemean = 'yes';
  1899. else
  1900. FTcfg.Timelock.removemean = 'no';
  1901. end
  1902. DropdownOptions = get(handles.DropdownCovCsdTime, 'String');
  1903. CovCsdWindow = DropdownOptions{get(handles.DropdownCovCsdTime, 'Value')};
  1904. switch CovCsdWindow
  1905. case 'All Time: Recommended'
  1906. PipeSettings.Freq.CsdWindow = 'all';
  1907. FTcfg.Timelock.covariancewindow = 'all';
  1908. case 'Analysis Window Only'
  1909. PipeSettings.Freq.CsdWindow = [handles.time.Start, handles.time.End];
  1910. FTcfg.Timelock.covariancewindow = [handles.time.Start, handles.time.End];
  1911. case 'Custom'
  1912. CovTimeStart = str2num(get(handles.TextboxCovCsdTimeStart, 'String'));
  1913. CovTimeEnd = str2num(get(handles.TextboxCovCsdTimeEnd, 'String'));
  1914. PipeSettings.Freq.CsdWindow = [CovTimeStart, CovTimeEnd];
  1915. FTcfg.Timelock.covariancewindow = [CovTimeStart, CovTimeEnd];
  1916. otherwise
  1917. error('Unrecognized Option');
  1918. end
  1919. % Read GUI to update frequency analysis settings:
  1920. DropdownOptions = get(handles.DropdownFreqMethod, 'String');
  1921. FreqMethod = DropdownOptions{get(handles.DropdownFreqMethod, 'Value')};
  1922. FreqStart = str2num(get(handles.TextboxFreqFoiStart, 'String'));
  1923. FreqEnd = str2num(get(handles.TextboxFreqFoiEnd, 'String'));
  1924. FreqRes = str2num(get(handles.TextboxFreqRes, 'String'));
  1925. switch FreqMethod
  1926. case 'mtmconvol: Fixed Time Win.'
  1927. FTcfg.Freq.method = 'mtmconvol';
  1928. message = {'Warning:'; '';
  1929. 'For mtmconvol with fixed time-windows, start and end frequency';
  1930. 'should be divisible by the frequency resolution.'};
  1931. if round(FreqStart / FreqRes) ~= (FreqStart / FreqRes)
  1932. FreqStart = FreqRes;
  1933. set(handles.TextboxFreqFoiStart, 'String', num2str(FreqStart));
  1934. msgbox(message, 'Warning:');
  1935. end
  1936. if round(FreqEnd / FreqRes) ~= (FreqEnd / FreqRes)
  1937. FreqEnd = round(FreqEnd / FreqRes) * FreqRes;
  1938. set(handles.TextboxFreqFoiEnd, 'String', num2str(FreqEnd));
  1939. msgbox(message, 'Warning:');
  1940. end
  1941. case 'mtmconvol: Freq. Dep. Time Win.'
  1942. FTcfg.Freq.method = 'mtmconvol';
  1943. case 'mtmfft'
  1944. FTcfg.Freq.method = 'mtmfft';
  1945. case 'wavelet'
  1946. FTcfg.Freq.method = 'wavelet';
  1947. case 'tfr'
  1948. FTcfg.Freq.method = 'tfr';
  1949. otherwise
  1950. error('Unrecognized option.');
  1951. end
  1952. handles.gui.FreqMethod = FreqMethod;
  1953. handles.gui.FreqStart = FreqStart;
  1954. handles.gui.FreqEnd = FreqEnd;
  1955. handles.gui.FreqRes = FreqRes;
  1956. % Enable/Disable GUI components:
  1957. set(findall(handles.PanelTimeFreqAnalysis, '-property', 'Enable'), 'Enable', 'on');
  1958. if ~strcmp(CovCsdWindow, 'Custom')
  1959. set(handles.TextboxCovCsdTimeStart, 'Enable', 'off');
  1960. set(handles.TextboxCovCsdTimeEnd, 'Enable', 'off');
  1961. set(handles.TextCovCsdTimeStart, 'Enable', 'off');
  1962. set(handles.TextCovCsdTimeEnd, 'Enable', 'off');
  1963. set(handles.TextCovCsdCustomTimeHeader, 'Enable', 'off');
  1964. end
  1965. % Set output handles:
  1966. handles.PipeSettings = PipeSettings;
  1967. handles.FTcfg = FTcfg;
  1968. OutputHandles = handles;
  1969. %--- Load time/freq analysis settings: ---%
  1970. %-----------------------------------------%
  1971. function OutputHandles = LoadTimeFreqSettings(InputHandles, LoadedMat)
  1972. handles = InputHandles;
  1973. time = handles.time;
  1974. FTcfg = handles.FTcfg;
  1975. PipeSettings = handles.PipeSettings;
  1976. % Load settings:
  1977. FTcfg.Timelock.removemean = LoadedMat.FTcfg.Timelock.removemean;
  1978. FTcfg.Timelock.covariancewindow = LoadedMat.FTcfg.Timelock.covariancewindow;
  1979. PipeSettings.Freq.CsdWindow = LoadedMat.PipeSettings.Freq.CsdWindow;
  1980. FTcfg.Freq.method = LoadedMat.FTcfg.Freq.method;
  1981. handles.gui.FreqMethod = LoadedMat.gui.FreqMethod;
  1982. handles.gui.FreqStart = LoadedMat.gui.FreqStart;
  1983. handles.gui.FreqEnd = LoadedMat.gui.FreqEnd;
  1984. handles.gui.FreqRes = LoadedMat.gui.FreqRes;
  1985. % Load COV demean:
  1986. if strcmp(FTcfg.Timelock.removemean, 'yes')
  1987. set(handles.CheckboxCovDemean, 'Value', 1);
  1988. else
  1989. set(handles.CheckboxCovDemean, 'Value', 0);
  1990. end
  1991. % Load time selection type for COV/CSD:
  1992. if strcmp(FTcfg.Timelock.covariancewindow, 'all')
  1993. CovCsdTime = 'All Time: Recommended';
  1994. elseif isequal(FTcfg.Timelock.covariancewindow, [time.Start, time.End])
  1995. CovCsdTime = 'Analysis Window Only';
  1996. else
  1997. CovCsdTime = 'Custom';
  1998. end
  1999. DropdownOptions = get(handles.DropdownCovCsdTime, 'String');
  2000. DropdownValue = find(strcmp(DropdownOptions, CovCsdTime));
  2001. set(handles.DropdownCovCsdTime, 'Value', DropdownValue);
  2002. if isempty(DropdownValue)
  2003. error('Option does not exist in dropdown list.'); % error-check
  2004. end
  2005. % Load custom COV/CSD time:
  2006. if strcmp(CovCsdTime, 'Custom')
  2007. TimeStart = num2str(FTcfg.Timelock.covariancewindow(1), '%1.3f');
  2008. TimeEnd = num2str(FTcfg.Timelock.covariancewindow(2), '%1.3f');
  2009. set(handles.TextboxCovCsdTimeStart, 'String', TimeStart);
  2010. set(handles.TextboxCovCsdTimeEnd, 'String', TimeEnd);
  2011. end
  2012. % Load freq analysis settings:
  2013. DropdownOptions = get(handles.DropdownFreqMethod, 'String');
  2014. DropdownValue = find(strcmp(DropdownOptions, LoadedMat.gui.FreqMethod));
  2015. set(handles.DropdownFreqMethod, 'Value', DropdownValue);
  2016. if isempty(DropdownValue)
  2017. error('Option does not exist in dropdown list.'); % error-check
  2018. end
  2019. set(handles.TextboxFreqFoiStart, 'String', num2str(LoadedMat.gui.FreqStart));
  2020. set(handles.TextboxFreqFoiEnd, 'String', num2str(LoadedMat.gui.FreqEnd));
  2021. set(handles.TextboxFreqRes, 'String', num2str(LoadedMat.gui.FreqRes));
  2022. % Set output handles:
  2023. handles.PipeSettings = PipeSettings;
  2024. handles.FTcfg = FTcfg;
  2025. OutputHandles = handles;
  2026. %--- Reset time/freq analysis settings: ---%
  2027. %------------------------------------------%
  2028. function OutputHandles = ResetTimeFreqSettings(InputHandles)
  2029. handles = InputHandles;
  2030. FTcfg = handles.FTcfg;
  2031. PipeSettings = handles.PipeSettings;
  2032. % Reset settings:
  2033. FTcfg.Timelock.removemean = 'no';
  2034. FTcfg.Timelock.covariancewindow = 'all';
  2035. PipeSettings.Freq.CsdWindow = 'all';
  2036. FTcfg.Freq.method = 'mtmfft';
  2037. handles.gui.FreqMethod = 'mtmfft';
  2038. handles.gui.FreqStart = 2;
  2039. handles.gui.FreqEnd = 50;
  2040. handles.gui.FreqRes = 2;
  2041. % Reset GUI panel:
  2042. set(handles.CheckboxCovDemean, 'Value', 0);
  2043. set(handles.DropdownCovCsdTime, 'Value', 1);
  2044. set(handles.TextboxCovCsdTimeStart, 'String', []);
  2045. set(handles.TextboxCovCsdTimeEnd, 'String', []);
  2046. set(handles.DropdownFreqMethod, 'Value', 1);
  2047. set(handles.TextboxFreqFoiStart, 'String', num2str(handles.gui.FreqStart));
  2048. set(handles.TextboxFreqFoiEnd, 'String', num2str(handles.gui.FreqEnd));
  2049. set(handles.TextboxFreqRes, 'String', num2str(handles.gui.FreqRes));
  2050. % Set output handles:
  2051. handles.PipeSettings = PipeSettings;
  2052. handles.FTcfg = FTcfg;
  2053. OutputHandles = handles;
  2054. %=========================================%
  2055. % FUNCTIONS FOR SOURCE ANALYSIS SETTINGS: %
  2056. %=========================================%
  2057. %--- GUI functions for source analysis: ---%
  2058. %------------------------------------------%
  2059. % User selects source method here:
  2060. function DropdownSourceMethod_Callback(hObject, eventdata, handles)
  2061. DropdownOptions = get(handles.DropdownSourceMethod, 'String');
  2062. SourceMethod = DropdownOptions{get(handles.DropdownSourceMethod, 'Value')};
  2063. if ismember(SourceMethod, {'dics', 'pcc'})
  2064. message = {'Warning:'; '';
  2065. 'DICS and PCC source methods run on frequency-domain data';
  2066. 'output from frequency analysis (ft_freqanalysis).'; '';
  2067. 'All other methods are for time-domain data output from';
  2068. 'timelocked analysis (ft_timelockanalysis).'};
  2069. msgbox(message, 'Warning:')
  2070. else
  2071. message = {'Note:'; '';
  2072. 'All source methods except for DICS and PCC run on time-domain data';
  2073. 'output from timelocked analysis (ft_timelockanalysis).'; '';
  2074. 'DICS and PCC source methods run on frequency-domain data.'};
  2075. msgbox(message, 'Note:')
  2076. end
  2077. if strcmp(SourceMethod, 'mne')
  2078. message = {'Warning:';
  2079. 'Freesurfer & MNESuite mesh generation not implemented yet.';
  2080. 'Mesh from headmodel generation will be used instead.'};
  2081. msgbox(message, 'Warning:')
  2082. end
  2083. handles = UpdateSourceSettings(handles);
  2084. guidata(hObject, handles);
  2085. % User selects source output statistic here:
  2086. function DropdownSourceOutput_Callback(hObject, eventdata, handles)
  2087. handles = UpdateSourceSettings(handles);
  2088. guidata(hObject, handles);
  2089. % User selects type of source contrast here:
  2090. function PanelSourceAnalysis_SelectionChangeFcn(hObject, eventdata, handles)
  2091. handles = UpdateSourceSettings(handles);
  2092. guidata(hObject, handles);
  2093. % Checkbox for EstNoise Common Filter:
  2094. function CheckboxEstNoiseCommonFilt_Callback(hObject, eventdata, handles)
  2095. handles = UpdateSourceSettings(handles);
  2096. guidata(hObject, handles);
  2097. %--- User enters start time for contrasting baseline: ---%
  2098. %--------------------------------------------------------%
  2099. function TextboxDiffBaseStart_Callback(hObject, eventdata, handles)
  2100. BaselineStart = str2num(get(handles.TextboxDiffBaseStart, 'String'));
  2101. BaselineEnd = str2num(get(handles.TextboxDiffBaseEnd, 'String'));
  2102. if isempty(BaselineStart)
  2103. msgbox('Error: Baseline time for DiffBase not specified.', 'Error:')
  2104. return;
  2105. end
  2106. if BaselineStart > BaselineEnd
  2107. msgbox('Error: Baseline start is greater than end.', 'Error:')
  2108. set(handles.TextboxDiffBaseStart, 'String', []);
  2109. return;
  2110. end
  2111. handles = UpdateSourceSettings(handles);
  2112. guidata(hObject, handles);
  2113. %--- User enters end time for contrasting baseline: ---%
  2114. %------------------------------------------------------%
  2115. function TextboxDiffBaseEnd_Callback(hObject, eventdata, handles)
  2116. BaselineStart = str2num(get(handles.TextboxDiffBaseStart, 'String'));
  2117. BaselineEnd = str2num(get(handles.TextboxDiffBaseEnd, 'String'));
  2118. if isempty(BaselineEnd)
  2119. msgbox('Error: Baseline end time not specified.', 'Error:')
  2120. set(handles.TextboxDiffBaseEnd, 'String', []);
  2121. return;
  2122. end
  2123. if BaselineEnd < BaselineStart
  2124. msgbox('Error: Baseline end cannot be less than start.', 'Error:')
  2125. set(handles.TextboxDiffBaseEnd, 'String', []);
  2126. return;
  2127. end
  2128. handles = UpdateSourceSettings(handles);
  2129. guidata(hObject, handles);
  2130. %--- Executes on button press in ButtonCommonFilterCond. ---%
  2131. %--------------------------------------------------------------%
  2132. function ButtonCommonFilterCond_Callback(hObject, eventdata, handles)
  2133. if isempty(handles.gui.RootpathFolders) || isempty(handles.gui.DetectedCondIDs)
  2134. return;
  2135. end
  2136. % Set common filter CondID for EstNoise:
  2137. FolderIndex = get(handles.ListboxRootpathFolders, 'Value');
  2138. RootpathFolder = handles.gui.RootpathFolders{FolderIndex};
  2139. CondIndex = get(handles.ListboxDetectedCondIDs, 'Value');
  2140. TargetCondID = handles.gui.DetectedCondIDs{CondIndex};
  2141. FolderCondString = [RootpathFolder,': ',TargetCondID];
  2142. handles.gui.CommonFilterCondID{1} = TargetCondID;
  2143. handles.gui.CommonFilterCondID{2} = RootpathFolder;
  2144. handles.gui.CommonFilterCondID{3} = FolderCondString;
  2145. % Update GUI:
  2146. handles = UpdateSourceSettings(handles);
  2147. % Save handles:
  2148. guidata(hObject, handles);
  2149. %--- Executes on button press in ButtonDiffCondControl. ---%
  2150. %-------------------------------------------------------------%
  2151. function ButtonDiffCondControl_Callback(hObject, eventdata, handles)
  2152. if isempty(handles.gui.RootpathFolders) || isempty(handles.gui.DetectedCondIDs)
  2153. return;
  2154. end
  2155. % Set control CondID for DiffCond:
  2156. FolderIndex = get(handles.ListboxRootpathFolders, 'Value');
  2157. RootpathFolder = handles.gui.RootpathFolders{FolderIndex};
  2158. CondIndex = get(handles.ListboxDetectedCondIDs, 'Value');
  2159. TargetCondID = handles.gui.DetectedCondIDs{CondIndex};
  2160. FolderCondString = [RootpathFolder,': ',TargetCondID];
  2161. handles.gui.ControlCondID{1} = TargetCondID;
  2162. handles.gui.ControlCondID{2} = RootpathFolder;
  2163. handles.gui.ControlCondID{3} = FolderCondString;
  2164. % Update GUI:
  2165. handles = UpdateSourceSettings(handles);
  2166. % Save handles:
  2167. guidata(hObject, handles);
  2168. %--- Detect input MEG files for common-filter / control: ---%
  2169. %-----------------------------------------------------------%
  2170. function OutputHandles = DetectCommonFiltControlData(InputHandles)
  2171. handles = InputHandles;
  2172. % Start Waitbox:
  2173. WaitBox = StartWaitBox('UPDATING COMMON-FILTER / CONTROL DATA:');
  2174. % Update common-filter & control dataset paths:
  2175. handles.gui.CommonFiltDataFiles = [];
  2176. handles.gui.ControlDataFiles = [];
  2177. for g = 1:length(handles.name.GroupID)
  2178. for s = 1:length(handles.name.SubjID{g})
  2179. if ~isempty(handles.gui.CommonFilterCondID)
  2180. Rootpath = handles.paths.Rootpath;
  2181. RootpathFolder = handles.gui.CommonFilterCondID{2};
  2182. GroupFolder = ['GroupID_',handles.name.GroupID{g}];
  2183. CondID = handles.gui.CommonFilterCondID{1};
  2184. NameData = [handles.name.SubjID{g}{s},'_PreprocMEG.mat'];
  2185. handles.gui.CommonFiltDataFiles{g}{s} = ...
  2186. [Rootpath,'/',RootpathFolder,'/',GroupFolder,'/',CondID,'/',NameData];
  2187. end
  2188. if ~isempty(handles.gui.ControlCondID)
  2189. Rootpath = handles.paths.Rootpath;
  2190. RootpathFolder = handles.gui.ControlCondID{2};
  2191. GroupFolder = ['GroupID_',handles.name.GroupID{g}];
  2192. CondID = handles.gui.ControlCondID{1};
  2193. NameData = [handles.name.SubjID{g}{s},'_PreprocMEG.mat'];
  2194. handles.gui.ControlDataFiles{g}{s} = ...
  2195. [Rootpath,'/',RootpathFolder,'/',GroupFolder,'/',CondID,'/',NameData];
  2196. end
  2197. end % Subj
  2198. end % Group
  2199. % Set output handles:
  2200. OutputHandles = handles;
  2201. close(WaitBox);
  2202. %--- Textbox to display selected common-filter or control CondID: ---%
  2203. %--------------------------------------------------------------------%
  2204. function TextboxCommonFiltControlCond_Callback(hObject, eventdata, handles)
  2205. PipeSettings = handles.PipeSettings;
  2206. EnteredText = get(handles.TextboxCommonFiltControlCond, 'String');
  2207. if strcmp(PipeSettings.Source.Contrast, 'EstNoise') && ...
  2208. strcmp(PipeSettings.Source.EstNoiseCommonFilt, 'yes')
  2209. if ~isempty(handles.gui.CommonFilterCondID) && ...
  2210. ~isequal(EnteredText, handles.gui.CommonFilterCondID{3})
  2211. set(handles.TextboxCommonFiltControlCond, 'String', handles.gui.CommonFilterCondID{3});
  2212. msgbox('Note: Use button to change common-filter CondID.')
  2213. end
  2214. elseif strcmp(PipeSettings.Source.Contrast, 'DiffCond')
  2215. if ~isempty(handles.gui.ControlCondID) && ...
  2216. ~isequal(EnteredText, handles.gui.ControlCondID{3})
  2217. set(handles.TextboxCommonFiltControlCond, 'String', handles.gui.ControlCondID{3});
  2218. msgbox('Note: Use button to change control CondID.')
  2219. end
  2220. end
  2221. %--- Executes on button press in ButtonSourceAdvSettings. ---%
  2222. %------------------------------------------------------------%
  2223. function ButtonSourceAdvSettings_Callback(hObject, eventdata, handles)
  2224. if isempty(handles.paths.Rootpath)
  2225. msgbox('Warning: Please select root directory first.', 'Warning:');
  2226. return;
  2227. end
  2228. if isempty(handles.name.AnalysisID) || isempty(handles.paths.AnalysisID)
  2229. msgbox('Warning: Create or load AnalysisID first.', 'Warning:');
  2230. return;
  2231. end
  2232. %** Opens settings .m file: Upgrade to sub-GUI later (Make it modal).
  2233. % - Can run child GUI, then call: uiwait(gcf) OR waitfor(childGUI)
  2234. % - Have updatefcns read adv.settings output to update settings accordingly.
  2235. open([handles.paths.AnalysisID,'/SETTINGS/Settings_SourceAnalysis.m']);
  2236. %--- Updates source analysis settings: ---%
  2237. %-----------------------------------------%
  2238. function OutputHandles = UpdateSourceSettings(InputHandles)
  2239. handles = InputHandles;
  2240. FTcfg = handles.FTcfg;
  2241. PipeSettings = handles.PipeSettings;
  2242. % Read GUI to update source method:
  2243. DropdownOptions = get(handles.DropdownSourceMethod, 'String');
  2244. SourceMethod = DropdownOptions{get(handles.DropdownSourceMethod, 'Value')};
  2245. ViableOptions = {'lcmv', 'sam', 'dics', 'pcc', 'loreta', 'mne', 'rv', 'music', 'mvl'};
  2246. if ismember(SourceMethod, ViableOptions)
  2247. FTcfg.Source.method = SourceMethod;
  2248. else
  2249. error('Unrecognized Option.'); % error-check
  2250. end
  2251. % Read GUI to update source contrast:
  2252. if get(handles.ButtonSourceEstNoise, 'Value') == 1
  2253. PipeSettings.Source.Contrast = 'EstNoise';
  2254. if get(handles.CheckboxEstNoiseCommonFilt, 'Value') == 1
  2255. PipeSettings.Source.EstNoiseCommonFilt = 'yes';
  2256. if ~isempty(handles.gui.CommonFilterCondID)
  2257. set(handles.TextboxCommonFiltControlCond,...
  2258. 'String', handles.gui.CommonFilterCondID{3});
  2259. else
  2260. set(handles.TextboxCommonFiltControlCond, 'String', 'None Selected.');
  2261. end
  2262. else
  2263. PipeSettings.Source.EstNoiseCommonFilt = 'no';
  2264. set(handles.TextboxCommonFiltControlCond, 'String', 'None Selected.');
  2265. end
  2266. elseif get(handles.ButtonSourceDiffCond, 'Value') == 1
  2267. PipeSettings.Source.Contrast = 'DiffCond';
  2268. if ~isempty(handles.gui.ControlCondID)
  2269. set(handles.TextboxCommonFiltControlCond, 'String', handles.gui.ControlCondID{3});
  2270. else
  2271. set(handles.TextboxCommonFiltControlCond, 'String', 'None Selected.');
  2272. end
  2273. elseif get(handles.ButtonSourceDiffBase, 'Value') == 1
  2274. BaselineStart = str2num(get(handles.TextboxDiffBaseStart, 'String'));
  2275. BaselineEnd = str2num(get(handles.TextboxDiffBaseEnd, 'String'));
  2276. PipeSettings.Source.Contrast = 'DiffBase';
  2277. PipeSettings.Source.DiffBaseTime = [BaselineStart, BaselineEnd];
  2278. else
  2279. error('Unrecognized Option');
  2280. end
  2281. % Read GUI to update source output:
  2282. DropdownOptions = get(handles.DropdownSourceOutput, 'String');
  2283. SourceOutput = DropdownOptions{get(handles.DropdownSourceOutput, 'Value')};
  2284. switch SourceOutput
  2285. case 'PseudoZ'
  2286. PipeSettings.Source.Output = 'PseudoZ';
  2287. case 'PseudoT'
  2288. PipeSettings.Source.Output = 'PseudoT';
  2289. case 'PseudoF'
  2290. PipeSettings.Source.Output = 'PseudoF';
  2291. otherwise
  2292. error('Unrecognized Option'); % error-check
  2293. end
  2294. if ~strcmp(PipeSettings.Source.Output, 'PseudoZ') &&...
  2295. get(handles.ButtonSourceEstNoise, 'Value') == 1
  2296. message = {'Warning:'; 'Output for EstNoise must be in PseudoZ.'};
  2297. msgbox(message, 'Warning:');
  2298. PipeSettings.Source.Output = 'PseudoZ';
  2299. DropdownValue = find(strcmp(DropdownOptions, 'PseudoZ'));
  2300. set(handles.DropdownSourceOutput, 'Value', DropdownValue);
  2301. elseif strcmp(PipeSettings.Source.Output, 'PseudoZ') &&...
  2302. get(handles.ButtonSourceEstNoise, 'Value') == 0
  2303. message = {'Warning:'; 'PseudoZ output is only available for EstNoise.'};
  2304. msgbox(message, 'Warning:')
  2305. PipeSettings.Source.Output = 'PseudoF';
  2306. DropdownValue = find(strcmp(DropdownOptions, 'PseudoF'));
  2307. set(handles.DropdownSourceOutput, 'Value', DropdownValue);
  2308. end
  2309. % Enable/Disable GUI components:
  2310. set(findall(handles.PanelSourceAnalysis, '-property', 'Enable'), 'Enable', 'on');
  2311. if ~strcmp(PipeSettings.Source.Contrast, 'EstNoise')
  2312. set(handles.CheckboxEstNoiseCommonFilt, 'Enable', 'off');
  2313. set(handles.ButtonCommonFilterCond, 'Enable', 'off');
  2314. else
  2315. if get(handles.CheckboxEstNoiseCommonFilt, 'Value') == 0
  2316. set(handles.ButtonCommonFilterCond, 'Enable', 'off');
  2317. end
  2318. end
  2319. if ~strcmp(PipeSettings.Source.Contrast, 'DiffCond')
  2320. set(handles.ButtonDiffCondControl, 'Enable', 'off')
  2321. end
  2322. if ~ismember(PipeSettings.Source.Contrast, {'EstNoise', 'DiffCond'})
  2323. set(handles.TextboxCommonFiltControlCond, 'Enable', 'off');
  2324. set(handles.TextCommonFiltControlCondHeader, 'Enable', 'off');
  2325. elseif strcmp(PipeSettings.Source.Contrast, 'EstNoise') && ...
  2326. get(handles.CheckboxEstNoiseCommonFilt, 'Value') == 0
  2327. set(handles.TextboxCommonFiltControlCond, 'Enable', 'off');
  2328. set(handles.TextCommonFiltControlCondHeader, 'Enable', 'off');
  2329. end
  2330. if ~strcmp(PipeSettings.Source.Contrast, 'DiffBase')
  2331. set(handles.TextboxDiffBaseStart, 'Enable', 'off');
  2332. set(handles.TextboxDiffBaseEnd, 'Enable', 'off');
  2333. set(handles.TextDiffBaseStart, 'Enable', 'off');
  2334. set(handles.TextDiffBaseEnd, 'Enable', 'off');
  2335. end
  2336. % Redetect paths for common-filter & control datasets:
  2337. handles = DetectCommonFiltControlData(handles);
  2338. % Set output handles:
  2339. handles.PipeSettings = PipeSettings;
  2340. handles.FTcfg = FTcfg;
  2341. OutputHandles = handles;
  2342. %--- Load source analysis settings: ---%
  2343. %--------------------------------------%
  2344. function OutputHandles = LoadSourceSettings(InputHandles, LoadedMat)
  2345. handles = InputHandles;
  2346. FTcfg = handles.FTcfg;
  2347. PipeSettings = handles.PipeSettings;
  2348. % Load source settings:
  2349. FTcfg.Source.method = LoadedMat.FTcfg.Source.method;
  2350. PipeSettings.Source.Output = LoadedMat.PipeSettings.Source.Output;
  2351. PipeSettings.Source.Contrast = LoadedMat.PipeSettings.Source.Contrast;
  2352. PipeSettings.Source.EstNoiseCommonFilt = LoadedMat.PipeSettings.Source.EstNoiseCommonFilt;
  2353. PipeSettings.Source.DiffBaseTime = LoadedMat.PipeSettings.Source.DiffBaseTime;
  2354. handles.gui.CommonFilterCondID = LoadedMat.gui.CommonFilterCondID;
  2355. handles.gui.ControlCondID = LoadedMat.gui.ControlCondID;
  2356. % Load GUI source method:
  2357. DropdownOptions = get(handles.DropdownSourceMethod, 'String');
  2358. DropdownValue = find(strcmp(DropdownOptions, FTcfg.Source.method));
  2359. set(handles.DropdownSourceMethod, 'Value', DropdownValue);
  2360. if isempty(DropdownValue)
  2361. error('Option does not exist in dropdown list.'); % error-check
  2362. end
  2363. % Load GUI source output:
  2364. switch PipeSettings.Source.Output
  2365. case 'PseudoZ'
  2366. SourceOutput = 'PseudoZ';
  2367. case 'PseudoT'
  2368. SourceOutput = 'PseudoT';
  2369. case 'PseudoF'
  2370. SourceOutput = 'PseudoF';
  2371. otherwise
  2372. error('Unrecognized Option.'); % error-check
  2373. end
  2374. DropdownOptions = get(handles.DropdownSourceOutput, 'String');
  2375. DropdownValue = find(strcmp(DropdownOptions, SourceOutput));
  2376. set(handles.DropdownSourceOutput, 'Value', DropdownValue);
  2377. if isempty(DropdownValue)
  2378. error('Option does not exist in dropdown list.'); % error-check
  2379. end
  2380. % Load GUI source contrast:
  2381. switch PipeSettings.Source.Contrast
  2382. case 'EstNoise'
  2383. set(handles.ButtonSourceEstNoise, 'Value', 1);
  2384. if strcmp(PipeSettings.Source.EstNoiseCommonFilt, 'yes')
  2385. set(handles.CheckboxEstNoiseCommonFilt, 'Value', 1);
  2386. if ~isempty(handles.gui.CommonFilterCondID)
  2387. set(handles.TextboxCommonFiltControlCond,...
  2388. 'String', handles.gui.CommonFilterCondID{3});
  2389. else
  2390. set(handles.TextboxCommonFiltControlCond, 'String', 'None Selected.');
  2391. end
  2392. else
  2393. set(handles.CheckboxEstNoiseCommonFilt, 'Value', 0);
  2394. set(handles.TextboxCommonFiltControlCond, 'String', 'None Selected.');
  2395. end
  2396. case 'DiffCond'
  2397. set(handles.ButtonSourceDiffCond, 'Value', 1);
  2398. if ~isempty(handles.gui.ControlCondID)
  2399. set(handles.TextboxCommonFiltControlCond,...
  2400. 'String', handles.gui.ControlCondID{3});
  2401. else
  2402. set(handles.TextboxCommonFiltControlCond, 'String', 'None Selected.');
  2403. end
  2404. case 'DiffBase'
  2405. BaseStart = num2str(PipeSettings.Source.DiffBaseTime(1), '%1.3f');
  2406. BaseEnd = num2str(PipeSettings.Source.DiffBaseTime(2), '%1.3f');
  2407. set(handles.ButtonSourceDiffBase, 'Value', 1);
  2408. set(handles.TextboxDiffBaseStart, 'String', BaseStart);
  2409. set(handles.TextboxDiffBaseEnd, 'String', BaseEnd);
  2410. otherwise
  2411. error('Unrecognized Option.'); % error-check
  2412. end
  2413. % Redetect paths for common-filter & control datasets:
  2414. handles = DetectCommonFiltControlData(handles);
  2415. % Set output handles:
  2416. handles.PipeSettings = PipeSettings;
  2417. handles.FTcfg = FTcfg;
  2418. OutputHandles = handles;
  2419. %--- Reset source analysis settings: ---%
  2420. %---------------------------------------%
  2421. function OutputHandles = ResetSourceSettings(InputHandles)
  2422. handles = InputHandles;
  2423. FTcfg = handles.FTcfg;
  2424. PipeSettings = handles.PipeSettings;
  2425. % Reset source analysis settings:
  2426. FTcfg.Source.method = 'lcmv';
  2427. PipeSettings.Source.Output = 'PseudoZ';
  2428. PipeSettings.Source.Contrast = 'EstNoise';
  2429. PipeSettings.Source.EstNoiseCommonFilt = 'no';
  2430. PipeSettings.Source.DiffBaseTime = [];
  2431. handles.gui.CommonFilterCondID = [];
  2432. handles.gui.ControlCondID = [];
  2433. handles.gui.CommonFiltDataFiles = [];
  2434. handles.gui.ControlDataFiles = [];
  2435. % Reset GUI panel:
  2436. set(handles.DropdownSourceMethod, 'Value', 1);
  2437. set(handles.DropdownSourceOutput, 'Value', 1);
  2438. set(handles.ButtonSourceEstNoise, 'Value', 1);
  2439. set(handles.CheckboxEstNoiseCommonFilt, 'Value', 0);
  2440. set(handles.TextboxCommonFiltControlCond, 'String', 'None Selected');
  2441. set(handles.TextboxDiffBaseStart, 'String', []);
  2442. set(handles.TextboxDiffBaseEnd, 'String', []);
  2443. % Set output handles:
  2444. handles.PipeSettings = PipeSettings;
  2445. handles.FTcfg = FTcfg;
  2446. OutputHandles = handles;
  2447. %==============================================%
  2448. % FUNCTIONS FOR SOURCE NORMALISATION SETTINGS: %
  2449. %==============================================%
  2450. %--- Executes on button press in CheckboxResliceMri2Src. ---%
  2451. %-----------------------------------------------------------%
  2452. function CheckboxResliceMri2Src_Callback(hObject, eventdata, handles)
  2453. handles = UpdateNormaliseSettings(handles);
  2454. guidata(hObject, handles);
  2455. %--- Executes on button press in ButtonNormSettings. ---%
  2456. %-------------------------------------------------------%
  2457. function ButtonNormSettings_Callback(hObject, eventdata, handles)
  2458. if isempty(handles.paths.Rootpath)
  2459. msgbox('Warning: Select root directory first.', 'Warning:');
  2460. return;
  2461. end
  2462. if isempty(handles.name.AnalysisID) || isempty(handles.paths.AnalysisID)
  2463. msgbox('Warning: Create or load AnalysisID first.', 'Warning:');
  2464. return;
  2465. end
  2466. %** Opens settings .m file: Upgrade to sub-GUI later (Make it modal).
  2467. % - Can run child GUI, then call: uiwait(gcf) OR waitfor(childGUI)
  2468. % - Have updatefcns read adv.settings output to update settings accordingly.
  2469. open([handles.paths.AnalysisID,'/SETTINGS/Settings_SourceNormalise.m']);
  2470. %--- Update source norm. settings & GUI panel: ---%
  2471. %-------------------------------------------------%
  2472. function OutputHandles = UpdateNormaliseSettings(InputHandles)
  2473. handles = InputHandles;
  2474. PipeSettings = handles.PipeSettings;
  2475. if get(handles.CheckboxResliceMri2Src, 'Value') == 1
  2476. PipeSettings.NormSPM.ResliceMri2Src = 'yes';
  2477. else
  2478. PipeSettings.NormSPM.ResliceMri2Src = 'no';
  2479. end
  2480. % Set output handles:
  2481. handles.PipeSettings = PipeSettings;
  2482. OutputHandles = handles;
  2483. %--- Load source norm. settings & GUI panel: ---%
  2484. %-----------------------------------------------%
  2485. function OutputHandles = LoadNormaliseSettings(InputHandles, LoadedMat)
  2486. handles = InputHandles;
  2487. PipeSettings = handles.PipeSettings;
  2488. % Load settings:
  2489. PipeSettings.NormSPM.ResliceMri2Src = LoadedMat.PipeSettings.NormSPM.ResliceMri2Src;
  2490. % Load GUI panel:
  2491. if strcmp(PipeSettings.NormSPM.ResliceMri2Src, 'yes')
  2492. set(handles.CheckboxResliceMri2Src, 'Value', 1);
  2493. else
  2494. set(handles.CheckboxResliceMri2Src, 'Value', 0);
  2495. end
  2496. % Set output handles:
  2497. handles.PipeSettings = PipeSettings;
  2498. OutputHandles = handles;
  2499. %--- Reset source norm. settings & GUI panel: ---%
  2500. %------------------------------------------------%
  2501. function OutputHandles = ResetNormaliseSettings(InputHandles)
  2502. handles = InputHandles;
  2503. PipeSettings = handles.PipeSettings;
  2504. PipeSettings.NormSPM.ResliceMri2Src = 'no';
  2505. set(handles.CheckboxResliceMri2Src, 'Value', 0);
  2506. % Set output handles:
  2507. handles.PipeSettings = PipeSettings;
  2508. OutputHandles = handles;
  2509. %======================================%
  2510. % FUNCTIONS FOR NIFTI & AFNI SETTINGS: %
  2511. %======================================%
  2512. %--- GUI functions for NIFTI & AFNI settings: ---%
  2513. %------------------------------------------------%
  2514. function CheckboxKeepNifti3DFiles_Callback(hObject, eventdata, handles)
  2515. handles = UpdateNiftiAfniSettings(handles);
  2516. guidata(hObject, handles);
  2517. function CheckboxAfniNaNFix_Callback(hObject, eventdata, handles)
  2518. handles = UpdateNiftiAfniSettings(handles);
  2519. guidata(hObject, handles);
  2520. function DropdownAfniTemplate_Callback(hObject, eventdata, handles)
  2521. message = {'Warning: If files were normalised using this pipeline,';
  2522. 'keep the AFNI template in MNI!'};
  2523. msgbox(message, 'Warning:')
  2524. handles = UpdateNiftiAfniSettings(handles);
  2525. guidata(hObject, handles);
  2526. %--- Updates NIFTI & AFNI conversion settings: ---%
  2527. %-------------------------------------------------%
  2528. function OutputHandles = UpdateNiftiAfniSettings(InputHandles)
  2529. handles = InputHandles;
  2530. PipeSettings = handles.PipeSettings;
  2531. % Read GUI to update settings:
  2532. if get(handles.CheckboxKeepNifti3DFiles, 'Value') == 1
  2533. PipeSettings.Afni4D.KeepNifti3D = 'yes';
  2534. else
  2535. PipeSettings.Afni4D.KeepNifti3D = 'no';
  2536. end
  2537. if get(handles.CheckboxAfniNaNFix, 'Value') == 1
  2538. PipeSettings.Afni4D.NaNFix = 'yes';
  2539. else
  2540. PipeSettings.Afni4D.NaNFix = 'no';
  2541. end
  2542. DropdownOptions = get(handles.DropdownAfniTemplate, 'String');
  2543. AfniTemplate = DropdownOptions{get(handles.DropdownAfniTemplate, 'Value')};
  2544. ViableOptions = {'mni', 'tlrc', 'orig'};
  2545. if ismember(AfniTemplate, ViableOptions)
  2546. PipeSettings.Afni4D.Template = AfniTemplate;
  2547. else
  2548. error('Unrecognized Option.'); % error-check
  2549. end
  2550. % Set output handles:
  2551. handles.PipeSettings = PipeSettings;
  2552. OutputHandles = handles;
  2553. %--- Load NIFTI & AFNI conversion settings: ---%
  2554. %----------------------------------------------%
  2555. function OutputHandles = LoadNiftiAfniSettings(InputHandles, LoadedMat)
  2556. handles = InputHandles;
  2557. PipeSettings = handles.PipeSettings;
  2558. % Load settings:
  2559. PipeSettings.Afni4D.KeepNifti3D = LoadedMat.PipeSettings.Afni4D.KeepNifti3D;
  2560. PipeSettings.Afni4D.NaNFix = LoadedMat.PipeSettings.Afni4D.NaNFix;
  2561. PipeSettings.Afni4D.Template = LoadedMat.PipeSettings.Afni4D.Template;
  2562. % Load GUI panel:
  2563. if strcmp(PipeSettings.Afni4D.KeepNifti3D, 'yes')
  2564. set(handles.CheckboxKeepNifti3DFiles, 'Value', 1);
  2565. else
  2566. set(handles.CheckboxKeepNifti3DFiles, 'Value', 0);
  2567. end
  2568. if strcmp(PipeSettings.Afni4D.NaNFix, 'yes')
  2569. set(handles.CheckboxAfniNaNFix, 'Value', 1);
  2570. else
  2571. set(handles.CheckboxAfniNaNFix, 'Value', 0);
  2572. end
  2573. DropdownOptions = get(handles.DropdownAfniTemplate, 'String');
  2574. DropdownValue = find(strcmp(DropdownOptions, PipeSettings.Afni4D.Template));
  2575. set(handles.DropdownAfniTemplate, 'Value', DropdownValue);
  2576. if isempty(DropdownValue)
  2577. error('Option does not exist in dropdown list.'); % error-check
  2578. end
  2579. % Set output handles:
  2580. handles.PipeSettings = PipeSettings;
  2581. OutputHandles = handles;
  2582. %--- Reset NIFTI & AFNI conversion settings: ---%
  2583. %-----------------------------------------------%
  2584. function OutputHandles = ResetNiftiAfniSettings(InputHandles)
  2585. handles = InputHandles;
  2586. PipeSettings = handles.PipeSettings;
  2587. % Reset settings:
  2588. PipeSettings.Afni4D.KeepNifti3D = 'no';
  2589. PipeSettings.Afni4D.NaNFix = 'yes';
  2590. PipeSettings.Afni4D.Template = 'mni';
  2591. % Reset GUI panel:
  2592. set(handles.CheckboxAfniNaNFix, 'Value', 1);
  2593. set(handles.DropdownAfniTemplate, 'Value', 1);
  2594. % Set output handles:
  2595. handles.PipeSettings = PipeSettings;
  2596. OutputHandles = handles;
  2597. %=======================================%
  2598. % FUNCTIONS TO GENERATE PIPELINE PATHS: %
  2599. %=======================================%
  2600. function OutputHandles = UpdatePipelinePaths(InputHandles)
  2601. handles = InputHandles;
  2602. paths = handles.paths;
  2603. time = handles.time;
  2604. FTcfg = handles.FTcfg;
  2605. PipeSettings = handles.PipeSettings;
  2606. Rootpath = handles.paths.Rootpath;
  2607. AnalysisPath = handles.paths.AnalysisID;
  2608. % Get FreqMethod:
  2609. CurrentDir = pwd;
  2610. cd([paths.AnalysisID,'/SETTINGS/']);
  2611. [~, ~, cfgFreq, ~] = Settings_TimelockFreqAnalysis (handles);
  2612. FreqMethod = cfgFreq.method;
  2613. cd(CurrentDir);
  2614. %--- Set paths for input MEG & MRI data: ---%
  2615. %-------------------------------------------%
  2616. if ~isempty(handles.gui.AnatID)
  2617. paths.MRIdata = handles.gui.InputAnatFiles;
  2618. end
  2619. switch handles.gui.MEGdataFiletype
  2620. case 'Fieldtrip'
  2621. paths.MEGdata = handles.gui.InputDataFiles;
  2622. case 'NIFTI'
  2623. paths.Nifti4DNormSource = handles.gui.InputDataFiles;
  2624. case 'AFNI'
  2625. paths.Afni4DNormSource = handles.gui.InputDataFiles;
  2626. end
  2627. %--- Set paths for segmented & normalised MRI's: ---%
  2628. %---------------------------------------------------%
  2629. for g = 1:length(handles.name.GroupID)
  2630. for s = 1:length(handles.name.SubjID{g})
  2631. GroupFolder = ['GroupID_',handles.name.GroupID{g}];
  2632. NameSegMRI = [handles.name.SubjID{g}{s},'_SegMRI.mat'];
  2633. NameNormMRI = [handles.name.SubjID{g}{s},'_NormMRI.mat'];
  2634. NameNormMRINii = [handles.name.SubjID{g}{s},'_NormMRI.nii'];
  2635. NameNormMRIAfni = [handles.name.SubjID{g}{s},'_NormMRI+tlrc.BRIK'];
  2636. NameMRINii = [handles.name.SubjID{g}{s},'_PreprocMRI_RASorient.nii'];
  2637. NameMRIAfni = [handles.name.SubjID{g}{s},'_PreprocMRI_RASorient+tlrc.BRIK'];
  2638. % Segmented MRI paths:
  2639. paths.SegMRI{g}{s} = ...
  2640. [AnalysisPath,'/SEG_MRI/',GroupFolder,'/',NameSegMRI];
  2641. % Normalised MRI paths:
  2642. paths.NormMRI{g}{s} = ...
  2643. [AnalysisPath,'/NORM_MRI/',GroupFolder,'/',NameNormMRI];
  2644. paths.NormMRINii{g}{s} = ...
  2645. [AnalysisPath,'/NORM_MRI_Nifti/',GroupFolder,'/',NameNormMRINii];
  2646. paths.NormMRIAfni{g}{s} = ...
  2647. [AnalysisPath,'/NORM_MRI_Afni/',GroupFolder,'/',NameNormMRIAfni];
  2648. % Also get paths for PreprocMRI RASorient NIFTI & AFNI files:
  2649. paths.MRIdataNii{g}{s} = ...
  2650. [AnalysisPath,'/MRI_RASorient_Nifti/',GroupFolder,'/',NameMRINii];
  2651. paths.MRIdataAfni{g}{s} = ...
  2652. [AnalysisPath,'/MRI_RASorient_Afni/',GroupFolder,'/',NameMRIAfni];
  2653. end
  2654. end
  2655. %--- Set paths for Timelock & Freq analysis: ---%
  2656. %-----------------------------------------------%
  2657. for g = 1:length(handles.name.GroupID)
  2658. for s = 1:length(handles.name.SubjID{g})
  2659. for c = 1:length(handles.name.CondID)
  2660. GroupFolder = ['GroupID_',handles.name.GroupID{g}];
  2661. SubjID = handles.name.SubjID{g}{s};
  2662. CondID = handles.name.CondID{c};
  2663. TimeFolder = ['TIMELOCK_',time.str.StartEnd];
  2664. NameTime = [SubjID,'_timelock.mat'];
  2665. NameGFP = [SubjID,'_globalmeanfield.mat'];
  2666. FreqFolder = ['FREQ_',FreqMethod,'_',time.str.StartEnd];
  2667. NameFreq = [SubjID,'_freq.mat'];
  2668. paths.Timelock{g}{s,c} = ...
  2669. [AnalysisPath,'/',TimeFolder,'/',GroupFolder,'/',CondID,'/',NameTime];
  2670. paths.GlobalMeanField{g}{s,c} = ...
  2671. [AnalysisPath,'/',TimeFolder,'/',GroupFolder,'/',CondID,'/',NameGFP];
  2672. paths.Freq{g}{s,c} = ...
  2673. [AnalysisPath,'/',FreqFolder,'/',GroupFolder,'/',CondID,'/',NameFreq];
  2674. end
  2675. end
  2676. end
  2677. % Group-averaged timelock & freq analysis paths:
  2678. for g = 1:length(handles.name.GroupID)
  2679. for c = 1:length(handles.name.CondID)
  2680. GroupFolder = ['GroupID_',handles.name.GroupID{g}];
  2681. CondID = handles.name.CondID{c};
  2682. NumSubjStr = num2str(length(handles.name.SubjID{g}));
  2683. TimeFolder = ['TIMELOCK_',time.str.StartEnd];
  2684. NameTime = ['GrpAvg_',NumSubjStr,'subj_timelock.mat'];
  2685. NameGFP = ['GrpAvg_',NumSubjStr,'subj_globalmeanfield.mat'];
  2686. FreqFolder = ['FREQ_',FreqMethod,'_',time.str.StartEnd];
  2687. NameFreq = ['GrpAvg_',NumSubjStr,'subj_freq.mat'];
  2688. paths.TimelockGrpAvg{g}{c} = ...
  2689. [AnalysisPath,'/',TimeFolder,'/',GroupFolder,'/',CondID,'/',NameTime];
  2690. paths.GlobalMeanFieldGrpAvg{g}{c} = ...
  2691. [AnalysisPath,'/',TimeFolder,'/',GroupFolder,'/',CondID,'/',NameGFP];
  2692. paths.FreqGrpAvg{g}{c} = ...
  2693. [AnalysisPath,'/',FreqFolder,'/',GroupFolder,'/',CondID,'/',NameFreq];
  2694. end % Cond
  2695. end % Group
  2696. %--- Set paths for headmodel to source sections: ---%
  2697. %---------------------------------------------------%
  2698. for g = 1:length(handles.name.GroupID)
  2699. for s = 1:length(handles.name.SubjID{g})
  2700. for c = 1:length(handles.name.CondID)
  2701. GroupFolder = ['GroupID_',handles.name.GroupID{g}];
  2702. SubjID = handles.name.SubjID{g}{s};
  2703. CondID = handles.name.CondID{c};
  2704. % Headmodel & Leadfield paths:
  2705. HdmFolder = ['HDMLEAD_',FTcfg.Hdm.method,'_',num2str(FTcfg.Lead.grid.resolution),'mm'];
  2706. NameHdm = [SubjID,'_hdm.mat'];
  2707. NameLead = [SubjID,'_lead.mat'];
  2708. paths.Hdm{g}{s,c} = ...
  2709. [AnalysisPath,'/',HdmFolder,'/',GroupFolder,'/',CondID,'/',NameHdm];
  2710. paths.Lead{g}{s,c} = ...
  2711. [AnalysisPath,'/',HdmFolder,'/',GroupFolder,'/',CondID,'/',NameLead];
  2712. % Source filter paths:
  2713. switch PipeSettings.Source.Contrast
  2714. case 'EstNoise'
  2715. if strcmp(PipeSettings.Source.EstNoiseCommonFilt, 'yes')
  2716. CommonFiltCondID = handles.gui.CommonFilterCondID{1};
  2717. FilterFolder = ['CommonFilter_',CommonFiltCondID];
  2718. else
  2719. FilterFolder = ['Filter_',CondID];
  2720. end
  2721. case 'DiffCond'
  2722. ControlCondID = handles.gui.ControlCondID{1};
  2723. FilterFolder = ['CommonFilter_',CondID,'_',ControlCondID];
  2724. case 'DiffBase'
  2725. BaseStart = [num2str(PipeSettings.Source.DiffBaseTime(1), '%1.3f')];
  2726. BaseEnd = [num2str(PipeSettings.Source.DiffBaseTime(2), '%1.3f')];
  2727. FilterFolder = ['CommonFilter_',CondID,'_BaseTime_',BaseStart,'s_',BaseEnd,'s'];
  2728. end
  2729. paths.SourceFilter{g}{s,c} = [AnalysisPath,'/SOURCE_FILTER/',...
  2730. GroupFolder,'/',FilterFolder,'/',SubjID,'_SourceFilter.mat'];
  2731. % Source COV / CSD file paths:
  2732. if ismember(FTcfg.Source.method, {'dics', 'pcc'})
  2733. SourceMethodDomain = 'Freq'; % DICS & PCC are for freq-domain data.
  2734. else
  2735. SourceMethodDomain = 'Time'; % All other methods are for time-domain data.
  2736. end
  2737. switch SourceMethodDomain
  2738. case 'Time'
  2739. paths.SourceCovCsd{g}{s,c} = [AnalysisPath,'/SOURCE_FILTER/',...
  2740. GroupFolder,'/',FilterFolder,'/',SubjID,'_COV.mat'];
  2741. case 'Freq'
  2742. paths.SourceCovCsd{g}{s,c} = [AnalysisPath,'/SOURCE_FILTER/',...
  2743. GroupFolder,'/',FilterFolder,'/',SubjID,'_CSD_',FreqMethod,'.mat'];
  2744. end
  2745. % Source analysis paths:
  2746. SrcMethod = FTcfg.Source.method;
  2747. SrcContrast = PipeSettings.Source.Contrast;
  2748. SrcOutput = PipeSettings.Source.Output;
  2749. SrcParams = [SrcMethod,'_',SrcContrast,'_',SrcOutput,'_',time.str.StartEnd];
  2750. paths.SourceFolder{g}{s,c} = ...
  2751. [AnalysisPath,'/SOURCE_',SrcParams,'/',GroupFolder,'/',CondID,'/',SubjID];
  2752. paths.SourceNiiFolder{g}{s,c} = ...
  2753. [AnalysisPath,'/SOURCE_RASorient_Nifti3D/',GroupFolder,'/',CondID,'/',SubjID];
  2754. paths.NormSourceFolder{g}{s,c} = ...
  2755. [AnalysisPath,'/NORM_SOURCE/',GroupFolder,'/',CondID,'/',SubjID];
  2756. paths.NormSourceNiiFolder{g}{s,c} = ...
  2757. [AnalysisPath,'/NORM_SOURCE_Nifti3D/',GroupFolder,'/',CondID,'/',SubjID];
  2758. for t = 1:size(time.Windows, 1)
  2759. paths.Source{g}{s,c,t} = [paths.SourceFolder{g}{s,c}, ...
  2760. '/Source_',time.str.Windows{t,3},'.mat'];
  2761. paths.SourceNii{g}{s,c,t} = [paths.SourceNiiFolder{g}{s,c}, ...
  2762. '/InterpSourceRAS_',time.str.Windows{t,3},'.nii'];
  2763. paths.NormSource{g}{s,c,t} = [paths.NormSourceFolder{g}{s,c}, ...
  2764. '/NormSource_',time.str.Windows{t,3},'.mat'];
  2765. paths.NormSourceNii{g}{s,c,t} = [paths.NormSourceNiiFolder{g}{s,c}, ...
  2766. '/NormSource_',time.str.Windows{t,3},'.nii'];
  2767. end
  2768. end % Cond
  2769. end % Subj
  2770. end % Group
  2771. %--- Set paths for group-averaged normsource files: ---%
  2772. %------------------------------------------------------%
  2773. for g = 1:length(handles.name.GroupID)
  2774. for c = 1:length(handles.name.CondID)
  2775. NumSubjStr = num2str(length(handles.name.SubjID{g}));
  2776. GroupFolder = ['GroupID_',handles.name.GroupID{g}];
  2777. CondID = handles.name.CondID{c};
  2778. paths.GrpAvgFolder{g}{c} = [AnalysisPath, ...
  2779. '/NORM_SOURCE/',GroupFolder,'/',CondID,'/GrpAvg_',NumSubjStr,'subj'];
  2780. paths.GrpAvgNiiFolder{g}{c} = [AnalysisPath, ...
  2781. '/NORM_SOURCE_Nifti3D/',GroupFolder,'/',CondID,'/GrpAvg_',NumSubjStr,'subj'];
  2782. for t = 1:size(time.Windows, 1)
  2783. paths.GrpAvg{g}{c,t} = [paths.GrpAvgFolder{g}{c}, ...
  2784. '/GrpAvg_',time.str.Windows{t,3},'.mat'];
  2785. paths.GrpAvgNii{g}{c,t} = [paths.GrpAvgNiiFolder{g}{c}, ...
  2786. '/GrpAvg_',time.str.Windows{t,3},'.nii'];
  2787. end
  2788. end % Cond
  2789. end % Group
  2790. %--- Set paths for Custom-Filter & Control datasets: ---%
  2791. %-------------------------------------------------------%
  2792. % Set paths for common-filter datasets:
  2793. if ~isempty(handles.gui.CommonFilterCondID)
  2794. paths.MEGdataCommonFilt = handles.gui.CommonFiltDataFiles;
  2795. end
  2796. % Set paths for control condition datasets:
  2797. if ~isempty(handles.gui.ControlCondID)
  2798. paths.MEGdataControl = handles.gui.ControlDataFiles;
  2799. for g = 1:length(handles.name.GroupID)
  2800. for s = 1:length(handles.name.SubjID{g})
  2801. GroupFolder = ['GroupID_',handles.name.GroupID{g}];
  2802. SubjID = handles.name.SubjID{g}{s};
  2803. CondID = handles.gui.ControlCondID{1};
  2804. % Source analysis paths:
  2805. paths.SourceControlFolder{g}{s} = ...
  2806. [AnalysisPath,'/SOURCE_',SrcParams,'/',GroupFolder,'/',CondID,'/',SubjID];
  2807. for t = 1:size(time.Windows, 1)
  2808. paths.SourceControl{g}{s,t} = [paths.SourceControlFolder{g}{s}, ...
  2809. '/Source_',time.str.Windows{t,3},'.mat'];
  2810. end
  2811. end % Subj
  2812. end % Group
  2813. end
  2814. %--- Set paths for NIFTI4D and AFNI4D files: ---%
  2815. %-----------------------------------------------%
  2816. for g = 1:length(handles.name.GroupID)
  2817. for s = 1:length(handles.name.SubjID{g})
  2818. for c = 1:length(handles.name.CondID)
  2819. GroupFolder = ['GroupID_',handles.name.GroupID{g}];
  2820. SubjID = handles.name.SubjID{g}{s};
  2821. CondID = handles.name.CondID{c};
  2822. % NIFTI 4D paths for source & normsource:
  2823. Nii4DSrcFolder = ...
  2824. [AnalysisPath,'/SOURCE_RASorient_Nifti4D/',GroupFolder,'/',CondID];
  2825. Nii4DNormSrcFolder = ...
  2826. [AnalysisPath,'/NORM_SOURCE_Nifti4D/',GroupFolder,'/',CondID];
  2827. NameNii4D = [SubjID,'_Nifti4D.nii'];
  2828. if ~strcmp(handles.gui.MEGdataFiletype, 'NIFTI')
  2829. paths.Nifti4DSource{g}{s,c} = [Nii4DSrcFolder,'/',NameNii4D];
  2830. paths.Nifti4DNormSource{g}{s,c} = [Nii4DNormSrcFolder,'/',NameNii4D];
  2831. end
  2832. % AFNI 4D paths for source & normsource:
  2833. Afni4DSrcFolder = ...
  2834. [AnalysisPath,'/SOURCE_RASorient_Afni4D/',GroupFolder,'/',CondID];
  2835. Afni4DNormSrcFolder = ...
  2836. [AnalysisPath,'/NORM_SOURCE_Afni4D/',GroupFolder,'/',CondID];
  2837. NameAfni4D = [SubjID,'_Afni4D+tlrc.BRIK'];
  2838. if ~strcmp(handles.gui.MEGdataFiletype, 'AFNI')
  2839. paths.Afni4DSource{g}{s,c} = [Afni4DSrcFolder,'/',NameAfni4D];
  2840. paths.Afni4DNormSource{g}{s,c} = [Afni4DNormSrcFolder,'/',NameAfni4D];
  2841. end
  2842. end % Cond
  2843. end % Subj
  2844. end % Group
  2845. % NIFTI and AFNI 4D paths for group-average:
  2846. for g = 1:length(handles.name.GroupID)
  2847. for c = 1:length(handles.name.CondID)
  2848. NumSubjStr = num2str(length(handles.name.SubjID{g}));
  2849. GroupFolder = ['GroupID_',handles.name.GroupID{g}];
  2850. CondID = handles.name.CondID{c};
  2851. Nii4DGrpAvgFolder = [AnalysisPath,'/NORM_SOURCE_Nifti4D/',GroupFolder,'/',CondID];
  2852. NameNii4D = ['GrpAvg_',NumSubjStr,'subj_Nifti4D.nii'];
  2853. Afni4DGrpAvgFolder = [AnalysisPath,'/NORM_SOURCE_Afni4D/',GroupFolder,'/',CondID];
  2854. NameAfni4D = ['GrpAvg_',NumSubjStr,'subj_Afni4D+tlrc.BRIK'];
  2855. paths.Nifti4DGrpAvg{g}{c} = [Nii4DGrpAvgFolder,'/',NameNii4D];
  2856. paths.Afni4DGrpAvg{g}{c} = [Afni4DGrpAvgFolder,'/',NameAfni4D];
  2857. end % Cond
  2858. end % Group
  2859. % Set output handles:
  2860. handles.paths = paths;
  2861. OutputHandles = handles;
  2862. %--- Reset pipeline paths: ---%
  2863. %-----------------------------%
  2864. function OutputHandles = ResetPipelinePaths(InputHandles)
  2865. handles = InputHandles;
  2866. paths = handles.paths;
  2867. % Reset paths:
  2868. paths.MRIdata = [];
  2869. paths.MEGdata = [];
  2870. paths.MRIdataNii = [];
  2871. paths.MRIdataAfni = [];
  2872. paths.SegMRI = [];
  2873. paths.NormMRI = [];
  2874. paths.NormMRINii = [];
  2875. paths.NormMRIAfni = [];
  2876. paths.Hdm = [];
  2877. paths.Lead = [];
  2878. paths.Timelock = [];
  2879. paths.GlobalMeanField = [];
  2880. paths.Freq = [];
  2881. paths.TimelockGrpAvg = [];
  2882. paths.GlobalMeanFieldGrpAvg = [];
  2883. paths.FreqGrpAvg = [];
  2884. paths.SourceCovCsd = [];
  2885. paths.SourceFilter = [];
  2886. paths.SourceFolder = [];
  2887. paths.Source = [];
  2888. paths.SourceNiiFolder = [];
  2889. paths.SourceNii = [];
  2890. paths.NormSourceFolder = [];
  2891. paths.NormSource = [];
  2892. paths.NormSourceNiiFolder = [];
  2893. paths.NormSourceNii = [];
  2894. paths.GrpAvgFolder = [];
  2895. paths.GrpAvg = [];
  2896. paths.GrpAvgNiiFolder = [];
  2897. paths.GrpAvgNii = [];
  2898. paths.MEGdataCommonFilt = [];
  2899. paths.MEGdataControl = [];
  2900. paths.SourceControlFolder = [];
  2901. paths.SourceControl = [];
  2902. paths.Nifti4DSource = [];
  2903. paths.Nifti4DNormSource = [];
  2904. paths.Nifti4DGrpAvg = [];
  2905. paths.Afni4DSource = [];
  2906. paths.Afni4DNormSource = [];
  2907. paths.Afni4DGrpAvg = [];
  2908. % Set output handles:
  2909. handles.paths = paths;
  2910. OutputHandles = handles;
  2911. %================================%
  2912. % FUNCTION TO SAVE BUILDER .MAT: %
  2913. %================================%
  2914. %--- Executes on button press in ButtonSaveBuilderMat. ---%
  2915. %---------------------------------------------------------%
  2916. function ButtonSaveBuilderMat_Callback(hObject, eventdata, handles)
  2917. PipeSettings = handles.PipeSettings;
  2918. FTcfg = handles.FTcfg;
  2919. time = handles.time;
  2920. SourceContrast = PipeSettings.Source.Contrast;
  2921. EstNoiseCommonFilt = PipeSettings.Source.EstNoiseCommonFilt;
  2922. % Check initial paths:
  2923. if isempty(handles.paths.Rootpath)
  2924. msgbox('Error: Root directory has not been selected.', 'Error:');
  2925. return;
  2926. end
  2927. if isempty(handles.name.AnalysisID) || isempty(handles.paths.AnalysisID)
  2928. msgbox('Error: AnalysisID has not been specified.', 'Error:');
  2929. return;
  2930. end
  2931. % Make sure Rootpath & AnalysisID don't have spaces:
  2932. CheckSpaces1 = strfind(handles.paths.Rootpath, ' ');
  2933. CheckSpaces2 = strfind(handles.paths.AnalysisID, ' ');
  2934. if ~isempty(CheckSpaces1) || ~isempty(CheckSpaces2)
  2935. message = {'Error: Target directory or AnalysisID contains spaces.';
  2936. 'AFNI functions cannot read folder & file paths with spaces.';
  2937. 'AFNI functions are required for file conversions later on.'};
  2938. msgbox(message, 'Error:')
  2939. end
  2940. % Check for basic input settings:
  2941. if isempty(handles.name.GroupID)
  2942. msgbox('Error: Groups have not been added.', 'Error:');
  2943. return;
  2944. end
  2945. if isempty(handles.name.SubjID)
  2946. msgbox('Error: Subjects have not been added.', 'Error:')
  2947. return;
  2948. else
  2949. for g = 1:length(handles.name.GroupID)
  2950. if isempty(handles.name.SubjID{g})
  2951. msgbox('Error: Not all Groups have Subjects added.', 'Error:')
  2952. return;
  2953. end
  2954. end
  2955. end
  2956. if isempty(handles.name.CondID)
  2957. msgbox('Error: Conditions have not been added.', 'Error:')
  2958. return;
  2959. end
  2960. % Check input MEG and MRI files:
  2961. if isempty(handles.gui.AnatID)
  2962. msgbox('Error: AnatID has not been specified.', 'Error:');
  2963. return;
  2964. end
  2965. if isempty(handles.gui.InputAnatFiles) || isempty(handles.gui.StatusAnat)
  2966. msgbox('Error: Input MRI files not specified.', 'Error:');
  2967. return;
  2968. end
  2969. if isempty(handles.gui.InputDataFiles) || isempty(handles.gui.StatusData)
  2970. msgbox('Error: Input MEG files not specified.', 'Error:');
  2971. return;
  2972. end
  2973. for g = 1:length(handles.name.GroupID)
  2974. if max(cellfun(@isempty, handles.gui.InputAnatFiles{g})) > 0
  2975. msgbox('Warning: Update input MRI files & status first.', 'Warning:');
  2976. return;
  2977. end
  2978. if max(cellfun(@isempty, handles.gui.StatusAnat{g})) > 0
  2979. msgbox('Warning: Update input MRI files & status first.', 'Warning:');
  2980. return;
  2981. end
  2982. if max(cellfun(@isempty, handles.gui.InputDataFiles{g})) > 0
  2983. msgbox('Warning: Update input MEG files & status first.', 'Warning:');
  2984. return;
  2985. end
  2986. if max(cellfun(@isempty, handles.gui.StatusData{g})) > 0
  2987. msgbox('Warning: Update input MEG files & status first.', 'Warning:');
  2988. return;
  2989. end
  2990. end
  2991. % Load sample dataset to get time "boundaries":
  2992. SampleData = LoadFTmat(handles.gui.InputDataFiles{1}{1,1}, 'BuilderGUI');
  2993. if isempty(SampleData)
  2994. msgbox('Error: Could not load first dataset to check time-boundaries.', 'Error:')
  2995. return;
  2996. end
  2997. DataStart = SampleData.time{1}(1);
  2998. DataEnd = SampleData.time{1}(end);
  2999. Tolerance = (1 / SampleData.fsample) * 2; % tolerance of 2 samples
  3000. % Check time settings (Most already checked in previous sections):
  3001. StartTime = str2num(get(handles.TextboxTimeStart, 'String'));
  3002. EndTime = str2num(get(handles.TextboxTimeEnd, 'String'));
  3003. WindowSize = str2num(get(handles.TextboxWindowSize, 'String'));
  3004. TimeStep = str2num(get(handles.TextboxTimeStep, 'String'));
  3005. if isempty(StartTime)
  3006. msgbox('Error: Start time must be specified.', 'Error:');
  3007. return;
  3008. end
  3009. if isempty(EndTime)
  3010. msgbox('Error: End time must be specified.', 'Error:');
  3011. return;
  3012. end
  3013. if isempty(WindowSize)
  3014. msgbox('Error: Window size must be specified.', 'Error:');
  3015. return;
  3016. end
  3017. if isempty(TimeStep)
  3018. msgbox('Error: Time step must be specified.', 'Error:');
  3019. return;
  3020. end
  3021. if StartTime < (DataStart - Tolerance) || StartTime > DataEnd
  3022. msgbox('Error: Start analysis time is outside of bounds of dataset time.', 'Error:');
  3023. set(handles.TextboxTimeStart, 'String', num2str(DataStart - Tolerance, '%1.3f'));
  3024. return;
  3025. end
  3026. if EndTime > (DataEnd + Tolerance) || EndTime < DataStart
  3027. msgbox('Error: End analysis time is outside bounds of dataset time.', 'Error:');
  3028. set(handles.TextboxTimeEnd, 'String', num2str(DataEnd + Tolerance, '%1.3f'));
  3029. return;
  3030. end
  3031. % Check freq settings:
  3032. FreqStart = str2num(get(handles.TextboxFreqFoiStart, 'String'));
  3033. FreqEnd = str2num(get(handles.TextboxFreqFoiEnd, 'String'));
  3034. FreqRes = str2num(get(handles.TextboxFreqRes, 'String'));
  3035. if isempty(FreqStart)
  3036. msgbox('Error: Start frequency must be specified.', 'Error:');
  3037. return;
  3038. end
  3039. if isempty(FreqEnd)
  3040. msgbox('Error: End frequency must be specified.', 'Error:');
  3041. return;
  3042. end
  3043. if isempty(FreqRes)
  3044. msgbox('Error: Frequency resolution must be specified.', 'Error:');
  3045. return;
  3046. end
  3047. if strcmp(handles.gui.FreqMethod, 'mtmconvol: Fixed Time Win.')
  3048. TotalAnalysisTime = handles.time.End - handles.time.Start;
  3049. FixedTimeWinSize = 1 / FreqRes;
  3050. if FixedTimeWinSize > TotalAnalysisTime
  3051. message = {'ERROR:'; '';
  3052. 'The size of the fixed time-window for frequency analysis is larger';
  3053. ['than the current total analysis time (',num2str(TotalAnalysisTime),' s).']; '';
  3054. 'For the method "mtmconvol" with fixed time-windows:';
  3055. 'Frequency resolution determines the size of the fixed time-window.'; '';
  3056. ['Current freq. resolution: ',num2str(FreqRes),'Hz'];
  3057. ['Fixed time-window size: ',num2str(1 / FreqRes),'s']; '';
  3058. 'Select a larger FreqRes value, or increase length of analysis window.'; ''};
  3059. msgbox(message, 'ERROR:');
  3060. set(handles.TextboxFreqRes, 'String', []);
  3061. return;
  3062. end
  3063. end
  3064. % Check custom COV / CSD time settings:
  3065. DropdownOptions = get(handles.DropdownCovCsdTime, 'String');
  3066. CovCsdWindow = DropdownOptions{get(handles.DropdownCovCsdTime, 'Value')};
  3067. if strcmp(CovCsdWindow, 'Custom')
  3068. CovCsdStart = str2num(get(handles.TextboxCovCsdTimeStart, 'String'));
  3069. CovCsdEnd = str2num(get(handles.TextboxCovCsdTimeEnd, 'String'));
  3070. if isempty(CovCsdStart)
  3071. msgbox('Error: Custom COV/CSD start time not specified.', 'Error:');
  3072. return
  3073. end
  3074. if isempty(CovCsdEnd)
  3075. msgbox('Error: Custom COV/CSD end time not specified.', 'Error:');
  3076. return;
  3077. end
  3078. if CovCsdStart < (DataStart - Tolerance) || CovCsdStart > DataEnd
  3079. msgbox('Error: Cov/Csd start time is outside of bounds of dataset time.', 'Error:')
  3080. set(handles.TextboxCovCsdTimeStart, 'String', num2str(DataStart - Tolerance, '%1.3f'));
  3081. return;
  3082. end
  3083. if CovCsdEnd > (DataEnd + Tolerance) || CovCsdEnd < DataStart
  3084. msgbox('Error: Cov/Csd end time is outside of bounds of dataset time.', 'Error:')
  3085. set(handles.TextboxCovCsdTimeEnd, 'String', num2str(DataEnd + Tolerance, '%1.3f'));
  3086. return;
  3087. end
  3088. end
  3089. % Check DiffBase time settings:
  3090. if strcmp(PipeSettings.Source.Contrast, 'DiffBase')
  3091. BaselineStart = str2num(get(handles.TextboxDiffBaseStart, 'String'));
  3092. BaselineEnd = str2num(get(handles.TextboxDiffBaseEnd, 'String'));
  3093. if isempty(BaselineStart)
  3094. msgbox('Error: Baseline time for DiffBase not specified.', 'Error:')
  3095. return;
  3096. end
  3097. if isempty(BaselineEnd)
  3098. msgbox('Error: Baseline end time not specified.', 'Error:')
  3099. return;
  3100. end
  3101. if BaselineStart < (DataStart - Tolerance) || BaselineStart > DataEnd
  3102. msgbox('Error: DiffBase baseline start is outside bounds of dataset time.', 'Error:')
  3103. set(handles.TextboxDiffBaseStart, 'String', num2str(DataStart - Tolerance, '%1.3f'));
  3104. return;
  3105. end
  3106. if BaselineEnd > (DataEnd + Tolerance) || BaselineEnd < DataStart
  3107. msgbox('Error: DiffBase baseline end is outside bounds of dataset time.', 'Error:')
  3108. set(handles.TextboxDiffBaseEnd, 'String', num2str(DataEnd + Tolerance, '%1.3f'));
  3109. return;
  3110. end
  3111. end
  3112. % Check analysis settings:
  3113. if isempty(time.Windows)
  3114. msgbox('Error: Time parameters not specified properly.', 'Error:')
  3115. return;
  3116. end
  3117. if isempty(FTcfg.Lead.grid.resolution)
  3118. msgbox('Error: Leadfield resolution not specified.', 'Error:')
  3119. return;
  3120. end
  3121. if strcmp(CovCsdWindow, 'Custom')
  3122. if isempty(FTcfg.Timelock.covariancewindow) || isempty(PipeSettings.Freq.CsdWindow)
  3123. msgbox('Error: Times for custom COV/CSD window not specified.', 'Error:')
  3124. return;
  3125. end
  3126. end
  3127. switch SourceContrast
  3128. case 'EstNoise'
  3129. if strcmp(EstNoiseCommonFilt, 'yes') && isempty(handles.gui.CommonFilterCondID)
  3130. msgbox('Error: Common filter CondID not selected.', 'Error:')
  3131. return;
  3132. end
  3133. case 'DiffCond'
  3134. if isempty(handles.gui.ControlCondID)
  3135. msgbox('Error: Control CondID not selected.', 'Error:')
  3136. return;
  3137. end
  3138. case 'DiffBase'
  3139. if isempty(PipeSettings.Source.DiffBaseTime)
  3140. msgbox('Error: DiffBase baseline time not specified.', 'Error:')
  3141. return;
  3142. end
  3143. end
  3144. % Check gradiometer info:
  3145. GradMismatch = CallCheckGradInfo(handles);
  3146. if GradMismatch == 1
  3147. open('ErrorLog_BuilderGUI.txt');
  3148. return;
  3149. end
  3150. % Confirm save:
  3151. ConfirmSave = questdlg('Save current settings into Builder .mat?',...
  3152. 'CONFIRM:', 'YES', 'NO', 'YES');
  3153. if strcmp(ConfirmSave, 'NO')
  3154. return;
  3155. end
  3156. BuilderPath = [handles.paths.AnalysisID,'/Builder_',handles.name.AnalysisID,'.mat'];
  3157. if exist(BuilderPath, 'file')
  3158. prompt = {'WARNING:'; '';
  3159. 'An existing Builder .mat file has been detected for this AnalysisID.'; '';
  3160. 'Do you wish to update and overwrite old configuration?'; ''};
  3161. OverwriteFile = questdlg(prompt, 'WARNING:', 'YES', 'NO', 'NO');
  3162. if strcmp(OverwriteFile, 'NO')
  3163. return;
  3164. end
  3165. end
  3166. % Start Waitbox:
  3167. WaitBox = StartWaitBox('SAVING SETTINGS TO BUILDER .MAT:');
  3168. % Update settings:
  3169. handles = UpdateGroupIDSettings (handles);
  3170. handles = UpdateSubjIDSettings (handles);
  3171. handles = UpdateCondIDSettings (handles);
  3172. handles = UpdateInputMRI (handles);
  3173. handles = UpdateInputMEG (handles);
  3174. handles = UpdateTimeSettings (handles);
  3175. handles = UpdateHdmLeadSettings (handles);
  3176. handles = UpdateTimeFreqSettings (handles);
  3177. handles = UpdateSourceSettings (handles);
  3178. handles = UpdateNormaliseSettings (handles);
  3179. handles = UpdateNiftiAfniSettings (handles);
  3180. % Generate paths:
  3181. handles = ResetPipelinePaths (handles);
  3182. handles = UpdatePipelinePaths (handles);
  3183. % Compile input & analysis settings:
  3184. name = handles.name;
  3185. paths = handles.paths;
  3186. time = handles.time;
  3187. gui = handles.gui;
  3188. FTcfg = handles.FTcfg; % Fields: Hdm, Lead, Timelock, Source
  3189. PipeSettings = handles.PipeSettings; % Fields: TimelockFreq, Source, Afni4D, NormSPM
  3190. % Acquire advanced settings from .m files:
  3191. CurrentDir = pwd;
  3192. cd([paths.AnalysisID,'/SETTINGS/']);
  3193. [FTcfg.SegMRI, FTcfg.Hdm, FTcfg.Lead] = Settings_SegHdmLeadfield(FTcfg);
  3194. [FTcfg.Timelock, FTcfg.TimelockAvg, FTcfg.GFP, FTcfg.Freq, FTcfg.FreqAvg] = Settings_TimelockFreqAnalysis(handles);
  3195. [FTcfg.Source, FTcfg.InterpSrc, FTcfg.WriteSrc, FTcfg.SrcAvg] = Settings_SourceAnalysis(FTcfg);
  3196. [SPMcfg, FTcfg.WriteNormMRI, FTcfg.WriteNormSrc] = Settings_SourceNormalise;
  3197. cd(CurrentDir);
  3198. % If ICAcleaned FT files selected, check if lambda on:
  3199. LambdaRequired = 0;
  3200. for g = 1:length(handles.name.GroupID)
  3201. if ~isempty(find(~cellfun(@isempty, handles.gui.CheckICAclean{g})))
  3202. LambdaRequired = 1;
  3203. end
  3204. end
  3205. if LambdaRequired == 1 && ~isfield(FTcfg.Source.(FTcfg.Source.method), 'lambda')
  3206. prompt = {'WARNING:'; '';
  3207. 'Detected ICA cleaning in one or more of the input MEG files.';
  3208. 'However, no REGULARIZATION (LAMBDA) has been set for source analysis.'; '';
  3209. 'For ICA cleaned data, it is HIGHLY RECOMMENDED to regularize the data';
  3210. 'for source analysis (Lambda = ''5%'' is a common value).'; '';
  3211. 'Do you wish to go back and set a regularization (lambda) value?'; ''};
  3212. CancelSave = questdlg(prompt, 'WARNING:', 'YES', 'NO', 'YES');
  3213. if strcmp(CancelSave, 'YES')
  3214. close(WaitBox);
  3215. return;
  3216. end
  3217. end
  3218. % Save settings:
  3219. CheckSavePath(BuilderPath, 'BuilderGUI');
  3220. save(BuilderPath, 'name', 'paths', 'time', 'gui', 'PipeSettings', 'FTcfg', 'SPMcfg');
  3221. % Feedback:
  3222. if exist(BuilderPath, 'file')
  3223. msgbox('Builder .mat file successfully saved.')
  3224. end
  3225. % Check for ErrorLog:
  3226. if exist([pwd,'/ErrorLog_BuilderGUI.txt'], 'file')
  3227. LogCheck = dir('ErrorLog_BuilderGUI.txt');
  3228. if LogCheck.bytes == 0 % File empty
  3229. delete('ErrorLog_BuilderGUI.txt');
  3230. end
  3231. end
  3232. close(WaitBox);
  3233. %==================================%
  3234. % FUNCTION TO CALL CHECKGRADINFO.m %
  3235. %==================================%
  3236. function GradMismatch = CallCheckGradInfo(InputHandles)
  3237. handles = InputHandles;
  3238. SourceContrast = handles.PipeSettings.Source.Contrast;
  3239. EstNoiseCommonFilt = handles.PipeSettings.Source.EstNoiseCommonFilt;
  3240. % Start Waitbox:
  3241. WaitBox = StartWaitBox('CHECKING GRADIOMETER INFO:');
  3242. % Check gradiometer info for Custom / Control datasets:
  3243. % Note: GradMismatch value is required for GeneratePipelinePaths.
  3244. % Therefore, we need to call paths from GUI fields.
  3245. TempHandles.name = handles.name;
  3246. TempHandles.gui.MEGdataFiletype = handles.gui.MEGdataFiletype;
  3247. TempHandles.PipeSettings.Source = handles.PipeSettings.Source;
  3248. TempHandles.paths.MEGdata = handles.gui.InputDataFiles;
  3249. TempHandles.paths.MEGdataCommonFilt = handles.gui.CommonFiltDataFiles;
  3250. TempHandles.paths.MEGdataControl = handles.gui.ControlDataFiles;
  3251. GradMismatch = CheckGradInfo(TempHandles, 'BuilderGUI');
  3252. if strcmp(SourceContrast, 'EstNoise') && ...
  3253. strcmp(EstNoiseCommonFilt, 'yes') && GradMismatch == 1
  3254. ErrMsg = {'========== ERROR: =========='; '';
  3255. 'Datasets from which common-filters are computed from do NOT have';
  3256. 'the same gradiometer info as their respective input datasets. ';
  3257. 'Therefore, common-filters cannot be applied. ';
  3258. '';
  3259. 'For each subject, the common-filter dataset and its respective ';
  3260. 'input datasets must have matching gradiometer info (usually ';
  3261. 'originating from the same MEG session). ';
  3262. '';
  3263. 'For a log of which input dataset(s) did not match with their ';
  3264. 'respective custom-filter datasets, see ErrorLog_BuilderGUI. '};
  3265. msgbox(ErrMsg, 'ERROR: Gradiometer Mismatch')
  3266. end
  3267. if strcmp(SourceContrast, 'DiffCond') && GradMismatch == 1
  3268. WarnMsg = {'========== ERROR: =========='; '';
  3269. 'Control datasets do NOT have the same gradiometer information ';
  3270. 'as their respective active condition datasets. Control and ';
  3271. 'active conditions cannot be merged for common-filter. ';
  3272. '';
  3273. 'As a result, the DiffCond setting (vs. Control Cond) cannot be ';
  3274. 'used. Gradiometer info must match (usually originating from ';
  3275. 'the same MEG session) in order for common-filter to be computed';
  3276. 'across active and control datasets.'
  3277. '';
  3278. 'For a log of which input dataset(s) did not match with their ';
  3279. 'respective control datasets, see ErrorLog_BuilderGUI. '};
  3280. msgbox(WarnMsg, 'ERROR: Gradiometer Mismatch')
  3281. end
  3282. close(WaitBox);
  3283. %=================================%
  3284. % FUNCTION TO OPEN MODAL WAITBOX: %
  3285. %=================================%
  3286. function WaitBox = StartWaitBox(TextString)
  3287. WaitBox = dialog('Units', 'pixels', 'Position', [500 500 300 40],...
  3288. 'Windowstyle', 'modal', 'NextPlot', 'new', 'Name', 'Please Wait:');
  3289. uicontrol('Parent', WaitBox, 'Units', 'pixels', 'Position', [20 10 250 20],...
  3290. 'Style', 'text', 'String', TextString, 'FontWeight', 'bold');
  3291. movegui(WaitBox, 'center');
  3292. %============================%
  3293. % GUIDE CREATEFCN FUNCTIONS: %
  3294. %============================%
  3295. % --- Executes during object creation, after setting all properties.
  3296. function TextboxRootpath_CreateFcn(hObject, eventdata, handles)
  3297. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  3298. set(hObject,'BackgroundColor','white');
  3299. end
  3300. % --- Executes during object creation, after setting all properties.
  3301. function TextboxAnalysisID_CreateFcn(hObject, eventdata, handles)
  3302. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  3303. set(hObject,'BackgroundColor','white');
  3304. end
  3305. % --- Executes during object creation, after setting all properties.
  3306. function ListboxGroupID_CreateFcn(hObject, eventdata, handles)
  3307. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  3308. set(hObject,'BackgroundColor','white');
  3309. end
  3310. % --- Executes during object creation, after setting all properties.
  3311. function ListboxSubjID_CreateFcn(hObject, eventdata, handles)
  3312. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  3313. set(hObject,'BackgroundColor','white');
  3314. end
  3315. % --- Executes during object creation, after setting all properties.
  3316. function TextboxSubjID_CreateFcn(hObject, eventdata, handles)
  3317. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  3318. set(hObject,'BackgroundColor','white');
  3319. end
  3320. % --- Executes during object creation, after setting all properties.
  3321. function DropdownMEGdataFiletype_CreateFcn(hObject, eventdata, handles)
  3322. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  3323. set(hObject,'BackgroundColor','white');
  3324. end
  3325. % --- Executes during object creation, after setting all properties.
  3326. function ListboxInputMEG_CreateFcn(hObject, eventdata, handles)
  3327. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  3328. set(hObject,'BackgroundColor','white');
  3329. end
  3330. % --- Executes during object creation, after setting all properties.
  3331. function ListboxInputMRI_CreateFcn(hObject, eventdata, handles)
  3332. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  3333. set(hObject,'BackgroundColor','white');
  3334. end
  3335. % --- Executes during object creation, after setting all properties.
  3336. function ListboxRootpathFolders_CreateFcn(hObject, eventdata, handles)
  3337. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  3338. set(hObject,'BackgroundColor','white');
  3339. end
  3340. % --- Executes during object creation, after setting all properties.
  3341. function ListboxDetectedCondIDs_CreateFcn(hObject, eventdata, handles)
  3342. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  3343. set(hObject,'BackgroundColor','white');
  3344. end
  3345. % --- Executes during object creation, after setting all properties.
  3346. function ListboxAddedCondIDs_CreateFcn(hObject, eventdata, handles)
  3347. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  3348. set(hObject,'BackgroundColor','white');
  3349. end
  3350. % --- Executes during object creation, after setting all properties.
  3351. function TextboxTimeStart_CreateFcn(hObject, eventdata, handles)
  3352. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  3353. set(hObject,'BackgroundColor','white');
  3354. end
  3355. % --- Executes during object creation, after setting all properties.
  3356. function TextboxWindowSize_CreateFcn(hObject, eventdata, handles)
  3357. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  3358. set(hObject,'BackgroundColor','white');
  3359. end
  3360. % --- Executes during object creation, after setting all properties.
  3361. function TextboxTimeStep_CreateFcn(hObject, eventdata, handles)
  3362. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  3363. set(hObject,'BackgroundColor','white');
  3364. end
  3365. % --- Executes during object creation, after setting all properties.
  3366. function TextboxTimeEnd_CreateFcn(hObject, eventdata, handles)
  3367. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  3368. set(hObject,'BackgroundColor','white');
  3369. end
  3370. % --- Executes during object creation, after setting all properties.
  3371. function DropdownHdmMethod_CreateFcn(hObject, eventdata, handles)
  3372. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  3373. set(hObject,'BackgroundColor','white');
  3374. end
  3375. % --- Executes during object creation, after setting all properties.
  3376. function TextboxLeadfieldRes_CreateFcn(hObject, eventdata, handles)
  3377. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  3378. set(hObject,'BackgroundColor','white');
  3379. end
  3380. % --- Executes during object creation, after setting all properties.
  3381. function DropdownCovCsdTime_CreateFcn(hObject, eventdata, handles)
  3382. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  3383. set(hObject,'BackgroundColor','white');
  3384. end
  3385. % --- Executes during object creation, after setting all properties.
  3386. function TextboxCovCsdTimeStart_CreateFcn(hObject, eventdata, handles)
  3387. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  3388. set(hObject,'BackgroundColor','white');
  3389. end
  3390. % --- Executes during object creation, after setting all properties.
  3391. function TextboxCovCsdTimeEnd_CreateFcn(hObject, eventdata, handles)
  3392. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  3393. set(hObject,'BackgroundColor','white');
  3394. end
  3395. % --- Executes during object creation, after setting all properties.
  3396. function DropdownFreqMethod_CreateFcn(hObject, eventdata, handles)
  3397. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  3398. set(hObject,'BackgroundColor','white');
  3399. end
  3400. % --- Executes during object creation, after setting all properties.
  3401. function TextboxFreqRes_CreateFcn(hObject, eventdata, handles)
  3402. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  3403. set(hObject,'BackgroundColor','white');
  3404. end
  3405. % --- Executes during object creation, after setting all properties.
  3406. function TextboxFreqFoiStart_CreateFcn(hObject, eventdata, handles)
  3407. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  3408. set(hObject,'BackgroundColor','white');
  3409. end
  3410. % --- Executes during object creation, after setting all properties.
  3411. function TextboxFreqFoiEnd_CreateFcn(hObject, eventdata, handles)
  3412. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  3413. set(hObject,'BackgroundColor','white');
  3414. end
  3415. % --- Executes during object creation, after setting all properties.
  3416. function DropdownSourceMethod_CreateFcn(hObject, eventdata, handles)
  3417. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  3418. set(hObject,'BackgroundColor','white');
  3419. end
  3420. % --- Executes during object creation, after setting all properties.
  3421. function DropdownSourceOutput_CreateFcn(hObject, eventdata, handles)
  3422. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  3423. set(hObject,'BackgroundColor','white');
  3424. end
  3425. % --- Executes during object creation, after setting all properties.
  3426. function TextboxCommonFiltControlCond_CreateFcn(hObject, eventdata, handles)
  3427. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  3428. set(hObject,'BackgroundColor','white');
  3429. end
  3430. % --- Executes during object creation, after setting all properties.
  3431. function TextboxDiffBaseStart_CreateFcn(hObject, eventdata, handles)
  3432. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  3433. set(hObject,'BackgroundColor','white');
  3434. end
  3435. % --- Executes during object creation, after setting all properties.
  3436. function TextboxDiffBaseEnd_CreateFcn(hObject, eventdata, handles)
  3437. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  3438. set(hObject,'BackgroundColor','white');
  3439. end
  3440. % --- Executes during object creation, after setting all properties.
  3441. function DropdownAfniTemplate_CreateFcn(hObject, eventdata, handles)
  3442. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  3443. set(hObject,'BackgroundColor','white');
  3444. end